1

I'm using chrome driver 74 and chrome browser version 74. I can able to execute the test cases in normal mode. But when I execute with headless mode, element not found exception is thrown. Any guess on how to solve this?

Tried with various window sizes as I see in many posts. But still, the issue persists.

Ex:

addArguments("window-size=1920,1080");
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
ARods
  • 441
  • 2
  • 5
  • 13
  • Do you have explicit wait in your code ? – cruisepandey May 27 '19 at 08:49
  • Yes. I've tried with FluentWait. The thing is everything works fine in normal mode. But not working in headless mode. – ARods May 27 '19 at 09:09
  • try with webdriverwait. – cruisepandey May 27 '19 at 09:10
  • @cruisepandey. Thanks for the reply. But I think wait doesn't help in this situation (I've already tested). Somehow the screen is not visible. I'm not sure how to debug with headless mode. It's happening with the latest chrome driver. I'm looking for an apt solution. – ARods May 27 '19 at 09:22
  • I have seen this case in an Gmail automation area in which it redirects the mail service request to two different versions of its interface depending on whether we go headless or not. Steps which you can perform: 1. Verify the list of elements shown in case of Normal execution versus Headless execution. - You can use driver.FindElements(By.Xpath("//input")) or by buttons 2. This will confirm you if the headless/non headless execution has same elements – Atul May 27 '19 at 13:32
  • If there is no difference then we are left with Waits, else you will have to modify the code as per the elements shown in headless mode(via findElements). – Atul May 27 '19 at 13:35
  • I've tried to check the page elements using driver.getPageSource(). I got the proper html response in non-headless mode. But in headless I got the empty html tags. – ARods May 28 '19 at 06:17
  • Thanks for all your replies. I've fixed the issue by setting up the normal chrome user agent value in chrome options instead of headless mode user agent value since my client site is not allowed to use headless mode user agent. This is the issue in my case. – ARods May 29 '19 at 06:43
  • Headless mode user agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/75.0.3770.51 Safari/537.36 I've replaced this with Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.51 Safari/537.36 In code: ChromeOptions options = new ChromeOptions(); options.addArguments("--user-agent=" + theAboveUserAgentValue); – ARods May 29 '19 at 06:43

0 Answers0