2014-09-23 55 views
0

我想在我的代碼中使用流暢的等待,但我得到Function(Function<Boolean> f = new Function<Boolean>())線錯誤。我使用流利的等待,但我不知道爲什麼我得到功能上的錯誤

FluentWait<WebElement> wait = new FluentWait<WebElement>(verificationtxt); 

wait.withTimeout(600, TimeUnit.SECONDS); 

wait.pollingEvery(5, TimeUnit.SECONDS); 

wait.ignoring(NoSuchElementException.class); 

Function<Boolean> f = new Function<Boolean>() 
     { 
    public Boolean apply(WebElement verificationtxt) 
    { 
     if(verificationtxt.getText().length()>0) 
     { 
      return true; 
     } 
     return false; 
    } 
     }; 
wait.until(f); 
+1

而你得到哪些錯誤? – olyv 2014-09-23 19:52:39

+0

看起來在字符串'txt'之前需要一個空格。 – djangofan 2014-09-23 20:43:30

+0

嗨olyv感謝您對此進行調查。我正在獲取函數關鍵字下方的紅線。當我將鼠標懸停在上面。它給了我建議來解決這個錯誤,我也嘗試了這個建議。 – 2014-09-25 12:01:26

回答

0

該線路應該是:

Function<WebElement, Boolean> f = new Function<WebElement, Boolean>() 

完整的源代碼:

封裝測試;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.FluentWait;

import com.google.common.base.Function;

公共類FluentWaitTest {

public void fluentWaitDemo() { 
    WebDriver driver = new FirefoxDriver(); 

    WebElement verificationtxt = driver.findElement(By.name("verificationtxt")); 

    FluentWait<WebElement> wait = new FluentWait<WebElement>(verificationtxt); 

    wait.withTimeout(600, TimeUnit.SECONDS); 

    wait.pollingEvery(5, TimeUnit.SECONDS); 

    wait.ignoring(NoSuchElementException.class); 

    Function<WebElement, Boolean> f = new Function<WebElement, Boolean>() { 
     public Boolean apply(WebElement verificationtxt) { 
      if (verificationtxt.getText().length() > 0) { 
       return true; 
      } 
      return false; 
     } 
    }; 
    wait.until(f); 
} 

}

+0

您好Sergii Pozharov – 2014-09-25 11:44:22

+0

您好Sergii Pozharov,謝謝您的回覆,我用過同樣的東西,但它仍然給我錯誤的功能。所以爲此我必須導入一些namespaces.cud你提供我示例代碼爲FluentWait.my mailid is [email protected]在此先感謝 – 2014-09-25 11:50:41

+0

嗨Anant Jain,我已經用完整的源代碼更新了答案。 你在用什麼IDE?在Eclipse中,您可以將鼠標懸停在錯誤上,它會向您建議您快速修復,包括導入所需的軟件包。 你能提供你有的確切的錯誤嗎? – 2014-09-25 20:10:05

相關問題