Karlla93
Karlla93

Reputation: 21

Selenium webdriver java wait for element present

I'm trying to make function wait for an element in Selenium.

private WebElement  waitIsClickable(By by, int n) throws Exception{

        WebDriverWait wait= new WebDriverWait(driver,/*seconds=*/ n);
        wait.until(ExpectedConditions.elementToBeClickable(by));

        return driver.findElement(by);
}

But when I want use it:

waitIsClickable(By.id("logIn"), 20).click();

I get an error:

Error:(1057, 20) java: method waitIsClickable in class Functions cannot be applied to given types; required: org.openqa.selenium.By,int found: org.openqa.selenium.By reason: actual and formal argument lists differ in length

Upvotes: 2

Views: 913

Answers (2)

Saurabh Gaur
Saurabh Gaur

Reputation: 23825

Your provided error stacktrace states expected two parameters while you are providing one which is By object. So you need check your calling reference again.

ExpectedConditions.elementToBeClickable returns either WebElement or throws TimeoutException if expected condition doesn't meet during wait, so no need to find element again. I would suggest you do some correction in waitIsClickable as below :-

private WebElement waitIsClickable(By by, long n) throws Exception {
    WebDriverWait wait= new WebDriverWait(driver, n);
    return wait.until(ExpectedConditions.elementToBeClickable(by));
 }

By by = By.id("logIn");
waitIsClickable(by, 20).click();

Upvotes: 0

dkmb
dkmb

Reputation: 41

Are you sure this is the line where error is? Do you have any other calls of this method? By the error description it seems you are trying to make a call as such:

waitIsClickable(By.id("logIn")).click();

Upvotes: 2

Related Questions