--headless flag no longer works after upgrade to chrome 76/chromedriver 76

你。 提交于 2019-12-13 03:38:56

问题


I am running python selenium tests using headless chrome. After updating to chrome Version 76.0.3809.87 and chromedriver version ChromeDriver 76.0.3809.68, the chromeOptions that I use (see code sample below)... no longer work. i.e. the browser is launched (non headless) and the resolution settings are also not working

Anyone else seeing this after upgrading to chromedriver 75/76?

chrome_options = {'args': ['headless', '--window-size=1920,1080', 'no-sandbox', '--dns-prefetch-disable','--disable-dev-shm-usage']}
capabilities = {'browserName': 'chrome', 'chromeOptions':chrome_options}
cls.driver = webdriver.Chrome(desired_capabilities=capabilities)

回答1:


You don't need to use desiredCapabilities to pass these arguments you can use Options instead. I have tested and it works.

Google Chrome - 76.0.3809.87

ChromeDriver - 76.0.3809.68

Selenium - 3.141.0

Python - 3.7.2

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)

driver.get('https://www.google.com')
driver.save_screenshot("screenshot.png")

driver.quit()

Check the screenshot obtained from the headless browser below.



来源:https://stackoverflow.com/questions/57379873/headless-flag-no-longer-works-after-upgrade-to-chrome-76-chromedriver-76

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!