Issue: Selenium Java Headless Mode (Chrome 130+) - Element Not Interactable, Stale Element & Timeout Issues

66 views
Skip to first unread message

Aashima Gandhi

unread,
Mar 13, 2025, 9:39:03 AM3/13/25
to Selenium Users
Hi ,

I am facing multiple issues while running Selenium Java tests in headless mode starting from Chrome 130. These tests work perfectly fine in headless = false mode (normal UI mode).

Errors encountered:

ElementNotInteractableException:

Caught org.openqa.selenium.ElementNotInteractableException: element not interactable | Retrying...

StaleElementReferenceException:

Caught org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found in the current frame | Retrying...

TimeoutException (Element not clickable):

Caught org.openqa.selenium.TimeoutException: Expected condition failed: waiting for condition (element to be clickable...) to be refreshed

I have tried multiple approaches to resolve the issues:

  1. Wait Strategies:

    • Used implicit and explicit waits (WebDriverWait) to ensure the elements are present before interacting.
    • Tried ExpectedConditions.elementToBeClickable() and ExpectedConditions.visibilityOfElementLocated().
  2. Re-Locating Elements:

    • Since stale element exceptions occurred, I tried finding the element again before interacting.
  3. JavaScript Execution:

    • Used JavascriptExecutor to click elements that were not interactable.
    • Used scrollIntoView() to make elements visible.
  4. ChromeOptions Tweaks:

    • Tried both --headless=new and --headless modes.
    • Used options like --disable-gpu--window-size=1920,1080, and --remote-allow-origins=*.
  5. Checking Element Visibility:

    • Used ExpectedConditions.frameToBeAvailableAndSwitchToIt() for frame handling.
What I am expecting 
  • I expected my Selenium tests to behave the same way in headless mode as they do in headless = false mode.
  • The elements should be visible, interactable, and clickable without throwing ElementNotInteractableExceptionStaleElementReferenceException, or TimeoutException.
  • The test should not require additional tweaks just because it is running in headless mode.

Questions

  1. Why do these issues occur only in headless mode (Chrome 130+)?
  2. Are there any additional ChromeOptions or workarounds to fix this?
  3. Is this related to a known Chromium bug affecting element interaction in headless mode?

Aashima Gandhi

unread,
Mar 13, 2025, 9:39:16 AM3/13/25
to Selenium Users
I am facing multiple issues while running Selenium Java tests in headless mode starting from Chrome 130. These tests work perfectly fine in headless = false mode (normal UI mode).

Errors encountered:

ElementNotInteractableException:


Caught org.openqa.selenium.ElementNotInteractableException: element not interactable | Retrying...

StaleElementReferenceException:


Caught org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found in the current frame | Retrying...

TimeoutException (Element not clickable):


Caught org.openqa.selenium.TimeoutException: Expected condition failed: waiting for condition (element to be clickable...) to be refreshed

I have tried multiple approaches to resolve the issues:

  1. Wait Strategies:

    • Used implicit and explicit waits (WebDriverWait) to ensure the elements are present before interacting.
    • Tried ExpectedConditions.elementToBeClickable() and ExpectedConditions.visibilityOfElementLocated().
  2. Re-Locating Elements:

    • Since stale element exceptions occurred, I tried finding the element again before interacting.
  3. JavaScript Execution:

    • Used JavascriptExecutor to click elements that were not interactable.
    • Used scrollIntoView() to make elements visible.
  4. ChromeOptions Tweaks:

    • Tried both --headless=new and --headless modes.
    • Used options like --disable-gpu, --window-size=1920,1080, and --remote-allow-origins=*.
  5. Checking Element Visibility:

    • Used ExpectedConditions.frameToBeAvailableAndSwitchToIt() for frame handling.

What I am expecting ?

Reply all
Reply to author
Forward
0 new messages