Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 938
user3395053 Avatar asked Apr 03 '17 08:04

user3395053


Video Answer


3 Answers

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

like image 64
beaucequebec Avatar answered Oct 12 '22 11:10

beaucequebec


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");
like image 23
Whizdom Trainings Avatar answered Oct 12 '22 12:10

Whizdom Trainings


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.

like image 40
Paras Avatar answered Oct 12 '22 13:10

Paras