3

i am trying to run the below selenium code :

        WebDriver driver;
        System.setProperty("webdriver.chrome.driver", "C:\\Driver\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("http://www.behsad.com/nportal/Default.aspx?tabid=55");

        driver.findElement(By.id("dnn_dnnUser_enhancedRegisterLink")).click();

        WebDriverWait wait=new WebDriverWait(driver, 30);
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(
                                        By.id("dnn_dnnUser_enhancedRegisterLink")));
        element.click();

here is my pom.xml:

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>1.2.5</version>
</dependency>

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.4.0</version>
</dependency>

and at the end there is the imports of the code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

the code gets stuck in the line:

WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(
                                            By.id("dnn_dnnUser_enhancedRegisterLink")));

and it complains with:

java.lang.NoSuchMethodError: org.openqa.selenium.support.ui.WebDriverWait.until(Lcom/google/common/base/Function;)Ljava/lang/Object;
Jeff
  • 7,767
  • 28
  • 85
  • 138
  • 2
    Possible duplicate of [wait.until(ExpectedConditions) doesnt work any more in selenium](http://stackoverflow.com/questions/42421148/wait-untilexpectedconditions-doesnt-work-any-more-in-selenium) – Moe Ghafari May 19 '17 at 20:50

3 Answers3

0

Selenium 3.1.0 onwards needs guava 21 for the wait.until method. Try adding this to your pom, preferable near the top in case another dependency is importing and older version of guava:

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>21.0</version>
</dependency>
snowstreams
  • 575
  • 2
  • 13
  • 23
sideshowmanny
  • 144
  • 2
  • 7
0

I think your problem is in this line of code

WebElement element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("dnn_dnnUser_enhancedRegisterLink")));

As Wait.until is used to tell your web driver to wait until a certain action to occur which is visibility of The element located by ID = "dnn_dnnUser_enhancedRegisterLink" in your case but this method Doesn't return a web element object so you can't use it to define a web element

Instead you just need to write :

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("dnn_dnnUser_enhancedRegisterLink")));
mohamed faisal
  • 177
  • 2
  • 12
0

It worked with latest jars:

Appium 1.8.1
Java-client 5.0.4
Selenium-java 3.7.1
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81