Selenium4 ERROR - wait.until(..)

177 views
Skip to first unread message

vendetta one

unread,
Oct 19, 2021, 11:18:55 PM10/19/21
to Selenium Users
Hello,

I`ve been reading the docs up and down regarding the following problem, to no avail:

With Selenium 3.141.59 it's possible to do the following:

Wait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofSeconds(3))
            .pollingEvery(Duration.ofSeconds(1)).ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("someID"));


(NOTE that it doesn't matter whether I use FluentWait or WebDriverWait)

However, since the upgrade to Selenium4 I get an error for aforementioned wait.until:
The method until(Function<? super WebDriver,T>) in the type Wait<WebDriver> is not applicable for the arguments (ExpectedCondition<WebElement>)

After some digging in docs and older tutorials I found out that originally there were supposed to be TWO methods of wait.until...one of them accepting a Function<? super T, V> as parameter, the other accepting a Predicate (the latter one of which is used in the code example above) (refer to e.g. here https://www.toolsqa.com/selenium-webdriver/advance-webdriver-waits/).
According to the API docs, with Selenium4 there is only the first method provided/implemented (https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/support/ui/Wait.html), BUT the official Selenium4 docs use the identical code that I'm using (the method getting a Predicate as parameter) (see https://www.selenium.dev/documentation/webdriver/waits/).

Does anyone know how I can fix this and if it's possibly a bug or w/e that the 2nd method (Predicate) doesn't exist anymore?

How can I change given code example to match the parameter requirements for the first method (Function)? (Sorry I'm kinda new to this)

Thanks in advance!

Serguei Kouzmine

unread,
Oct 20, 2021, 1:12:47 AM10/20/21
to Selenium Users
works perfectly fine for me with Selenium 4:

final int flexibleWait = 30;
final int implicitWait = 1;
final int pollingInterval = 500;
@SuppressWarnings("deprecation")
WebDriverWait wait = new WebDriverWait(driver, flexibleWait);
wait.pollingEvery(Duration.ofMillis(pollingInterval));

wait.until(ExpectedConditions
.presenceOfElementLocated(By.id("mw-content-text")));



Alexander Buss

unread,
Oct 20, 2021, 2:28:14 AM10/20/21
to seleniu...@googlegroups.com
Hi,

I have the same issue and didn't find a solution yet.

Alex

--
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/02b88a06-8f79-40c1-9f1e-031b7874737en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages