//Code
driver.get("https://demoqa.com/elements");
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
wait.withTimeout(Duration.ofSeconds(10));
wait.pollingEvery(Duration.ofSeconds(2));
wait.ignoring(NoSuchElementException.class); //exception ignored
Function<WebDriver, WebElement> fun = new Function<WebDriver, WebElement>() {
@Override
public WebElement apply(WebDriver t) {
WebElement element = t.findElement(By.xpath("//button[contains(@class,'text-danger')]"));
if (element!=null) {
System.out.println(element.getAttribute("class"));
return element;
}
long d = System.currentTimeMillis();
System.out.println(d);
return element;
}
};
WebElement element = wait.until(fun);
//rest of code
**Basically, the program should wait for dynamic element to change it's class name after some point and print the new class name.**
- The element that I written at first won’t have the expected “text-danger” in it. But after 5 sec it’s class changes and will eventually have that string at that point my code should get into the if and should print the class attribute. But instead it throws no such exception at the first attempt of finding the element.
Which must not happen as I ignored it in first place.
I have tried changing the timeout and Pooling time no improvement. Where I’m going Wrong.*
New contributor
YOGESH SHANKAR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.