Nefarious62
Nefarious62

Reputation: 171

Chrome page opened with selenium remains blank

I am trying to save a screenshot of a webpage, to do so I am trying to use Selenium. The problem is that once the webpage is opened, it stays blank with "data:" in the URL.

Here is my code:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options,executable_path='aPath/chromedriver.exe',service_log_path='aPath/mylog.txt')
driver.get('http://myURL.html')
screenshot=driver.save_screenshot('aPath/my_screenshot.png')
driver.quit()

NB: I have checked that my chromedriver version is compatible with my chrome browser version.

Upvotes: 3

Views: 6928

Answers (3)

Matt Austin
Matt Austin

Reputation: 1

I found that adding the following option worked for me:

options.add_argument('--no-sandbox')

Details found in this answer: selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages using ChromeDriver through Selenium

Upvotes: 0

Nefarious62
Nefarious62

Reputation: 171

Thanks for your help guys, actually Guy was right, I had to specify the port:

options.add_argument('--remote-debugging-port=9222')

Now it works!

Upvotes: 4

undetected Selenium
undetected Selenium

Reputation: 193108

You need to update the value of the Key executable_path with the absolute path of the chromedriver binary and service_args as follows:

driver = webdriver.Chrome(options=options,executable_path=r'C:\path\to\chromedriver.exe', service_args=["--log-path=C:\\path\\to\\mylog.log"])

You can find a couple of relevant discussions in:

Upvotes: 2

Related Questions