Intermittent error when checking element staleness in Chrome

563 views
Skip to first unread message

Iain

unread,
Feb 16, 2024, 12:12:24 PM2/16/24
to Selenium Users
Hi all,

I've recently started getting an intermittent error when using the following function to check a page transition:

void triggerPageTransition(Runnable runnable) {
     var htmlElement = getDriver().findElement(By.tagName("html"));
     runnable.run();
     new WebDriverWait(getDriver(), 10).until(ExpectedConditions.stalenessOf(htmlElement));
}

The error I'm getting is as follows:

org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32000,"message":"Node with given id does not belong to the document"} (Session info: chrome=121.0.6167.160) Build info: version: '4.17.0', revision: 'e52b1be057*' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.2.0-1019-azure', java.version: '14.0.2' Driver info: org.openqa.selenium.chrome.ChromeDriver Command: [0178910a3623c15563a0ee2fc779ffd5, isElementEnabled {id=8EC76C261FE08DED41ECCC5682F32B71_element_469}] Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 121.0.6167.160, chrome: {chromedriverVersion: 121.0.6167.85 (3f98d690ad7e..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:46137}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:cdp: ws://localhost:46137/devtoo..., se:cdpVersion: 121.0.6167.160, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true} Element: [[ChromeDriver: chrome on linux (0178910a3623c15563a0ee2fc779ffd5)] -> tag name: html] Session ID: 0178910a3623c15563a0ee2fc779ffd5 at java...@14.0.2/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java...@14.0.2/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java...@14.0.2/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java...@14.0.2/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java...@14.0.2/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at app//org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185) at app//org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:134) at app//org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:51) at app//org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:190) at app//org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:216) at app//org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:174) at app//org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:519) at app//org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:223) at app//org.openqa.selenium.remote.RemoteWebElement.isEnabled(RemoteWebElement.java:181) at app//org.openqa.selenium.support.ui.ExpectedConditions$24.apply(ExpectedConditions.java:700) at app//org.openqa.selenium.support.ui.ExpectedConditions$24.apply(ExpectedConditions.java:695) at app//org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)

It looks to me like this is a success case for the wait condition (the element is stale), but for some reason the error from Chrome is not being reliably converted to a StaleElementReferenceException?

I've applied a workaround of wrapping the staleness condition in an additional block that checks for an exception with that message, but I'm assuming that either I'm doing something wrong, or this is a bug somewhere in Selenium? Would be good to know what the correct thing to do is to fix this properly :)


princila roseline

unread,
Feb 18, 2024, 12:06:55 AM2/18/24
to seleniu...@googlegroups.com

The error you're encountering suggests that the element you're trying to interact with has become stale, meaning it is no longer attached to the DOM (Document Object Model). This typically occurs when the DOM is refreshed or the element is removed and replaced.

However, it seems like the exception being thrown is not the expected StaleElementReferenceException, which Selenium usually throws when an element becomes stale. Instead, you're getting a WebDriverException with an unknown error message.

This could be due to a few reasons:

  1. Timing Issue: Sometimes, Selenium WebDriver might not catch the exception at the right time due to timing issues in the application or the test script.

  2. WebDriver Implementation: There might be an issue with the WebDriver implementation itself, where it fails to properly catch and translate the error into a StaleElementReferenceException.

  3. Selenium Version Compatibility: Ensure that the version of Selenium WebDriver you're using is compatible with the browser version and ChromeDriver version you have. There might be compatibility issues that are causing unexpected behavior.

  4. Bug in Selenium: It's also possible that this behavior is a bug in Selenium WebDriver.

To handle this issue properly, you've done the right thing by implementing a workaround to catch the specific error message. This ensures that even if the exception type is not as expected, you can still handle the error appropriately.

If you suspect a bug in Selenium, you can report it to the Selenium project maintainers, providing all the relevant details and steps to reproduce the issue. They might be able to investigate further and provide a fix in a future release.



--
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/0ce2b495-a6b8-4d06-b5b7-76bf5aea2b4dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages