In web automation(selenium+java) when running code without a headless working fine but with headless{chrome} fails and i get error the element not found?

0 votes
when running code with headed, its working fine, but with headless{chrome} fails and I get error the element not found using XPATH .

TimeoutError: Waiting for element to be located By(xpath, /html/body/div[5]/ul/li/div[2]) Wait timed out after 30003ms

But it finds it with headed. any suggestions, limitation ?
Sep 8 in Selenium by mayur
• 120 points
151 views

1 answer to this question.

0 votes

For a headless browser, you have to set the window size.

options= Options()
options.add_argument('--headless')
options.add_argument('window-size=1920x1080');

answered Sep 8 by Karan
• 19,000 points
Why is setting the window size important for headless?
The problem is that headless mode is meant to be used on computers without screens, so there's no way for it to figure out what size your screen is even if you have one. The only way is for you to pass that information to the browser with --window-size.

The default window size and display size in headless mode is 800x600 on all platforms.

So the maximized window size is not applicable for chrome-headless and needs to be explicitly set by users, if required.

Related Questions In Selenium

+1 vote
2 answers
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,819 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,802 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,767 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,143 views
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13 in Selenium by Karan
• 19,000 points
2,743 views