WebDriverWait.until no longer available in Selenium-java-3.2 and Selenium-java-3.3 releases
Asked Answered
T

9

5

In Selenium-java-3.0.1, I can use WebDriverWait.until for explicit waits:

new WebDriverWait(myChromeDriver, 30).until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));

Above code was running well in Selenium-java-3.0.1, until we upgraded to Selenium-java-3.2 where class WebDriverWait disappear from client-combined-3.3.0-nodeps.jar all together.

What is the corresponding method call in Selenium 3.2/3.3? Thanks in advance.

Stack trace is as below:

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.WebDriverWait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;
    at au.com.testpro.rft2selenium.objects.TestObject.waitForLoad(Unknown Source)
    at au.com.testpro.rft2selenium.objects.TestObject.find(Unknown Source)
    at au.com.testpro.rft2selenium.objects.TestObject.find(Unknown Source)
    at test.ScriptSuperClass_JZ.findTestObject(ScriptSuperClass_JZ.java:65)
    at test.refData_Verify.execute(refData_Verify.java:102)
    at au.com.testpro.framework.java.superclasses.JavaFrameworkSuperClass.execute(Unknown Source)
    at au.com.testpro.framework.java.superclasses.JavaFrameworkSuperClass.executeCsv(Unknown Source)
    at test.refData_Verify.test(refData_Verify.java:486)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Til answered 3/4, 2017 at 8:4 Comment(0)
P
5

This Works in selenium 3 like this

WebDriverWait wait = new WebDriverWait(driver,20)
wait.until(ExpectedConditions.visibilityofElementLocatedBy(By.xpath("xxx");

On selenium 4 this looks like

WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(20))
wait.until(ExpectedConditions.visibilityofElementLocatedBy(By.xpath("xxx");
Periclean answered 11/8, 2020 at 12:29 Comment(0)
T
3

Quick fix if you are using the wait.until and don't want to change lots of things :

I had a global WebDriverWait wait before selenium 3.1.0 : WebDriverWait wait = new WebDriverWait(driver, 30, 5000);

I'm simply using this now in 3.3.1 (it works well for me): FluentWait wait = new FluentWait<>(driver) .withTimeout(30, SECONDS) .pollingEvery(5, SECONDS) .ignoring(NoSuchElementException.class);

Of course you need to have com.google.guava 21.0 as a dependency

Teakettle answered 3/5, 2017 at 19:21 Comment(0)
G
1

Please update the version of Guava jar that you are using to v-21, whenever there is a change in selenium-version, it is recommended to read the release notes, before start using the version.

Golgi answered 3/4, 2017 at 8:25 Comment(1)
Thanks Paras for pointing me to the release notes, it says Selenium-java-3.2 "Remove deprecated FluentWait.until(Predicate<?>) method. This should make lambdas work properly with Wait instances now." The problem is that Selenium-java-3.2 got rid of Wait class as well. How does explicit waits works now with Selenium-java-3.2 onward ? And what is Guava ?Til
T
1

You probably have old files and dublicate files that are conflicting. Change version package guava. Upgrade to guava-21.0.jar and this problem resoved. https://github.com/SeleniumHQ/selenium/issues/3880

For me removing old selenium.jar files and pointing to latest folder did the job.

Tassel answered 13/7, 2017 at 23:8 Comment(0)
G
0

Explicitly wait or conditional wait in Selenium 3.2/3.3.

WebDriverWait wait = new WebDriverWait(wb, 60);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("value")));

This will wait for every web element for 60 seconds.

Gatha answered 4/4, 2017 at 5:30 Comment(3)
Your example is exactly what worked for me but no longer does. That's the original poster's point. The syntax he was using was correct. This violates one of the biggest rules of programming (in my opinion): never remove a feature if it can be avoided. It always ticks somebody off. I'm hoping the example given of the fluent wait works for me.Culbreth
@Bill I had the same issue. I fixed it by using the not deprecated .until() method of WebDriverWait and by adding the following to my maven pom.xml: <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>21.0</version> </dependency> Other than that, my code looks exactly like before. To be more specific there are now two .until() methods. The old one (which is deprecated): public void until(final Predicate<T> isTrue) {} And the new one: public <V> V until(Function<? super T, V> isTrue) {}Gatha
I gave that a shot, and it caused my page object initialization to fail, somehow, which is strange because there are no references in the page object class to wait statements. I do have the app running now without any wait statements at all, but I appreciate your information. Should I need to use them again in the future, I will revisit this and see what might have caused the new problem.Culbreth
S
0

If you are using pom.xml and getting the same error again.Just go to C/user/yoursystemuser/.m2/repo/com/google/guava/guavaVersions.

Delete all the previous versions of guava and keep latest. Below is the link to the dependency for guava.You might have to check your selenium version as well.

https://mvnrepository.com/artifact/com.google.guava/guava/23.0

Swear answered 14/11, 2017 at 18:2 Comment(0)
C
0

i would suggest make a parameterized method and call it wherever you need it as per the conditions such as- waitinf for clickable,waiting for visibility,waiting for invisibility.methods are given below:-

//waits untill the element passed in method is not clickable.

public  void WaitForElementToBeClickable(WebElement element,long timeInSec)
{
    WebDriverWait wait=new WebDriverWait(driver, timeInSec );
    wait.until(ExpectedConditions.elementToBeClickable(element));
}
Circumgyration answered 1/4, 2019 at 9:43 Comment(0)
B
0

Update version of guava as 28.0-jre in pom.xml

Brutalize answered 22/7, 2019 at 11:34 Comment(0)
E
0

Use Duration.ofSeconds(30) instead of 30

WebDriverWait for Selenium 3

WebDriverWait wait = new WebDriverWait(myChromeDriver, 30) wait.until((ExpectedCondition) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));

WebDriverWait for Selenium 4

WebDriverWait wait = new WebDriverWait(myChromeDriver, Duration.ofSeconds(30)) wait.until((ExpectedCondition) wd -> ((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));

Enidenigma answered 15/10 at 10:54 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Madi

© 2022 - 2024 — McMap. All rights reserved.