简体   繁体   中英

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. 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.

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'. Use options.add_argument("user-agent=XXX") to override the user agent setting and see whether it solves the issue.
  2. AcceptLanguage header entry is not set while using headless (looks like a bug) Selenium doesn't allow setting HTTP headers. 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.

Code ChromeOptions options = new ChromeOptions(); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); Capabilities.setAcceptInsecureCerts(true); Options.merge(capabilities);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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