Chrome page opened with selenium remains blank

Question:

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.

Asked By: Nefarious62

||

Answers:

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:pathtochromedriver.exe', service_args=["--log-path=C:\path\to\mylog.log"])

You can find a couple of relevant discussions in:

Answered By: undetected Selenium

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!

Answered By: Nefarious62

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

Answered By: Matt Austin