在selenium中运行Function时,为了流畅的等待获取空指针异常

时间:2016-06-12 14:20:50

标签: java selenium

按钮为null

时的颜色
  

线程中的异常" main"显示java.lang.NullPointerException

public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new FirefoxDriver();
    driver.get("http://toolsqa.com/automation-practice-switch-windows/");

    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
    wait.pollingEvery(250,  TimeUnit.MILLISECONDS);
    wait.withTimeout(2, TimeUnit.SECONDS);

    Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>()
            {
                public Boolean apply(WebDriver arg0) {
                    WebElement element = arg0.findElement(By.id("colorVar"));
                    String color = element.getAttribute("color");
                    System.out.println("The color if the button is " + color);
                    if(color.equals("red"))
                    {
                        return true;
                    }
                    return false;
                }
            };

    wait.until(function);
}

0 个答案:

没有答案