--headless标志在升级到chrome 76 / chromedriver 76后不再起作用

时间:2019-08-06 15:55:04

标签: python selenium selenium-webdriver selenium-chromedriver

我正在使用无头铬进行python硒测试。在更新为chrome版本76.0.3809.87和chromedriver版本ChromeDriver 76.0.3809.68之后,我使用的chromeOptions(请参见下面的代码示例)...不再起作用。即启动浏览器(非无头)并且分辨率设置也不起作用

升级到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 个答案:

答案 0 :(得分:1)

您不需要使用desiredCapabilities来传递这些参数,而可以使用Options来代替。我已经测试过并且可以正常工作。

Google Chrome - 76.0.3809.87

ChromeDriver - 76.0.3809.68

- 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()

检查从下面的无头浏览器获得的屏幕截图。

Screenshot.png