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, 2020 in Selenium by mayur
• 120 points
4,090 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, 2020 by Karan
• 19,610 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,500 points
12,619 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,572 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,910 points
6,629 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 3, 2020 in Selenium by Sri
• 3,190 points
7,519 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, 2020 in Selenium by Karan
• 19,610 points
7,805 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP