2016-08-18 117 views
2

我试图让函数等待Selenium中的元素。Selenium webdriver java等待元素存在

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

但是,当我想用​​它:

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

我得到一个错误:

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

你确定这是在错误的行?你有任何其他这种方法的电话?到了错误的描述,似乎您试图拨打电话这样:

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

你提供的错误堆栈跟踪状态预计两个参数,而你是一个提供是By对象。所以你需要再次检查你的呼叫参考。

ExpectedConditions.elementToBeClickable返回或者WebElement或抛出TimeoutException如果预期条件不等待期间举行,因此没有必要再次找到元素。我建议你在waitIsClickable做一些修正如下: -

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

int参数将被装箱到很长时间。这不是问题(再次查看错误消息)。 – Guy

+0

@Guy哦,你是对的错误状态预计两个参数,而找到一个。感谢指出.. :) –

+0

@Guy但调用参考看起来不错,因为OP提供 –

相关问题