简体   繁体   English

在Chrome无头模式下执行硒测试

[英]Execution of Selenium Tests in Chrome headless mode

I am trying to run the application in chrome headless mode using the below code, while providing the application as Google.com the code runs fine, whereas when providing the actual application under test URL I get a blank page. 我正在尝试使用以下代码在Chrome无头模式下运行该应用程序,同时以Google.com的形式提供该应用程序,代码可以正常运行,而在测试网址下提供实际的应用程序时,我得到一个空白页。 Any idea how to rectify this? 任何想法如何纠正这一点?

Code: 码:

ChromeOptions options = new ChromeOptions();
Options.addArguments("--headless");
Webdriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");
System.out.println(driver.getTitle());

Chrome Version is 66. Chrome版本为66。

According to the discussion on this thread , there are only two differences. 根据对该线程的讨论,只有两个区别。

  1. UA string has a 'headless' in it and the browser is identified as 'HeadlessChrome'. UA字符串中包含“ headless”,并且浏览器被标识为“ HeadlessChrome”。 Use options.add_argument("user-agent=XXX") to override the user agent setting and see whether it solves the issue. 使用options.add_argument("user-agent=XXX")覆盖用户代理设置,并查看它是否可以解决问题。
  2. AcceptLanguage header entry is not set while using headless (looks like a bug) Selenium doesn't allow setting HTTP headers. 使用无头时未设置AcceptLanguage标头条目(看起来像个错误)Selenium不允许设置HTTP标头。 You can use workarounds discussed here . 您可以使用此处讨论的解决方法。

Thank you for the answers, i was able to resolve this looks the application that i was accessing has security error and any application running in headless chrome if it has security error opens a blank page this is how we can handle it. 谢谢您的回答,我能够解决这个问题,因为我正在访问的应用程序出现安全错误,如果有安全错误,任何在无头chrome中运行的应用程序都会打开空白页,这就是我们可以处理的方式。

Code ChromeOptions options = new ChromeOptions(); 代码ChromeOptions选项=新的ChromeOptions(); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); DesiredCapabilities功能= DesiredCapabilities.chrome(); Capabilities.setAcceptInsecureCerts(true); Capabilities.setAcceptInsecureCerts(真); Options.merge(capabilities); Options.merge(能力);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM