Scripts are not working headless mode - no such element found exception

822 views
Skip to first unread message

razz...@gmail.com

unread,
Dec 14, 2022, 11:45:11 AM12/14/22
to Selenium Users
Hi All,

I am facing an issue while running my java selenium scripts in headless mode. When I execute on non-headless mode everything works perfectly fine without any issue. 
But when I execute the same scripts in headless mode I am getting 'no such element found exception'. 
I am facing this issue majorly when there is page transition(As per my observation), I tried using debugger but still the same issue.

Could someone help to resolve this issue?


Thanks 
Manjuraj

David

unread,
Dec 14, 2022, 2:05:34 PM12/14/22
to Selenium Users
What scripts are you referring to? Your selenium code in python/ruby/javascript/node.js/etc.? Or did you mean execution of javascript code from the JavascriptExecutor in Selenium? Please clarify.

razz...@gmail.com

unread,
Dec 15, 2022, 2:12:42 AM12/15/22
to Selenium Users
My selenium code is in JAVA. I am using normal selenium command like driver.element.getText(),  driver.element.click(). 

razz...@gmail.com

unread,
Dec 16, 2022, 11:48:57 AM12/16/22
to Selenium Users
following code resolved my problem, 

driver.manage().window().setSize( new Dimension(1920,1080)  );

Thank you

David

unread,
Dec 16, 2022, 2:35:03 PM12/16/22
to Selenium Users
Interesting, how did you figure it out? What was the original dimensions of the headless window? I guess headless vs head mode uses different default window sizes?

Maicon Strey

unread,
Dec 18, 2022, 9:05:08 PM12/18/22
to Selenium Users

did you try to get a printscreen just before the error? so you will have shure that the page are loading properly.

do you have any proxy in your organization? if yes, did you configure the proxy on capabilities options?


Vinayak S Kori

unread,
Dec 26, 2022, 6:20:35 AM12/26/22
to seleniu...@googlegroups.com
Hi,

  1. Make sure that the element you are trying to locate is actually present in the DOM when the script is running.

  2. Make sure that the element you are trying to locate is visible and not hidden by other elements on the page. Selenium will not be able to locate hidden elements.

  3. Make sure that you are using the correct locator strategy to find the element. You can try using different locator strategies, such as class name, ID, or CSS selector, to see if that helps.

  4. You can try adding explicit waits to your script to allow more time for the page to load and the element to become available. You can use the WebDriverWait class to do this.

  5. If the element you are trying to locate is inside an iframe, you may need to switch to the iframe before attempting to locate the element. You can use the driver.switchTo().frame() method to do this.


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/52dcb2de-df16-4f9c-947c-047826a942d3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages