Dub*_*Dan 6 python selenium google-chrome selenium-chromedriver selenium-webdriver
我正在编写一个 selenium 测试,考虑到 chrome 浏览器是否以无头方式启动,该测试具有不同的行为。我的问题是在我的测试中如何检测浏览器是否对我的条件流无头?
driver.execute_script("return navigator.plugins.length == 0")
Run Code Online (Sandbox Code Playgroud)
小智 -1
当启动 chrome headless 实例时,您需要显式地将参数“--headless”添加到 chromeOptions 对象中。例如,如果您正在为网站编写测试框架,您可能拥有某种浏览器创建器类,该类能够为您提供不同的浏览器来使用。为什么不将该参数保存为该类的附加成员呢?
如果您的代码中没有这种工厂设计,另一个更简单的选择就是
options = webdriver.ChromeOptions
options.add_argument("--headless")
print(options.arguments)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2225 次 |
| 最近记录: |