Skip to content

[🐛 Bug]: Randomly getting java.lang.ClassCastException when trying to interact with a particular element #16389

@sjanard

Description

@sjanard

Description

  • after loading the page i am trying to click on a login link
  • ⁠i expect it to click
  • ⁠getting the following exception
REST API Reason:java.lang.ClassCastException: 
  class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.WebElement
    (java.util.LinkedHashMap is in module java.base of loader 'bootstrap';
     org.openqa.selenium.WebElement is in unnamed module of loader...
  • stacktrace :
java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class org.openqa.selenium.WebElement (java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; org.openqa.selenium.WebElement is in unnamed module of loader 'app')
	at org.openqa.selenium.remote.ElementLocation$ElementFinder$2.findElement(ElementLocation.java:166)
	at org.openqa.selenium.remote.ElementLocation.findElement(ElementLocation.java:59)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:367)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:361)
	at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:194)
	at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:190)
	at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:627)
	at org.openqa.selenium.support.ui.ExpectedConditions$22.apply(ExpectedConditions.java:624)
	at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:203)

Reproducible Code

public void tapLoginButton(WebDriver driver) {
    By loginLocator = By.xpath("//p[contains(text(),'Login')]");
    safeClick(driver, loginLocator, 10);
}

public void safeClick(WebDriver driver, By locator, int timeoutSeconds) {
    WebElement element = waitForElementClickable(driver, locator, timeoutSeconds);
    element.click();
}

public WebElement waitForElementClickable(WebDriver driver, By locator, int timeoutSeconds) {
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(timeoutSeconds));
    return wait.until(ExpectedConditions.elementToBeClickable(locator));
}

Other Information

  1. Locally does not seem to be happening
  2. Java version 11
  3. Observing this randomly on this particular point of our script on trying to interact with this <p class="D_le M_lK D_lf M_lL D_lj M_lP D_ll M_lR D_lp M_lV D_ls M_lY D_la" style="color:unset">Login</p>
  4. We tried this on browserstack chrome version 138/140 and OS 10 and 11
  5. sorry, cant share the URL
  6. We tried without waiting for the element to be clickable by directly clicking on the element, still got the same error

Metadata

Metadata

Assignees

Labels

C-javaJava BindingsI-defectSomething is not working as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions