2

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

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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();

4 Comments

The int parameter will be boxed to long. That is not the problem (look at the error message again).
@Guy oh yes you are right error states expected two param while found one. Thanks to point out..:)
@Guy But calling reference looks ok as OP provided
Assuming he/she actually posted the line witch gives the error, which I doubt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.