2016-08-18 121 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提供 –

相關問題