Reputation: 171
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
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
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
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