0

The color if the button is null

Exception in thread "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);
}
MikeCAT
  • 73,922
  • 11
  • 45
  • 70
  • Getting following exception The color if the button is null Exception in thread "main" java.lang.NullPointerException at Function_Test$1.apply(Function_Test.java:30) at Function_Test$1.apply(Function_Test.java:1) at org.openqa.selenium.support.ui.FluentWait$3.apply(FluentWait.java:207) at org.openqa.selenium.support.ui.FluentWait$3.apply(FluentWait.java:1) at org.openqa.selenium.support.ui.Flue – anirudha agnihotri Jun 12 '16 at 14:21
  • 1
    Don't call `color.equals()` when `color = null` – MikeCAT Jun 12 '16 at 14:21
  • Comment is not for putting such a long information. Please edit your question to include it. – MikeCAT Jun 12 '16 at 14:22
  • To the OP... in the future, make sure you put all relevant info in the question itself so that readers can more easily find all the info you provided. If you post your question and then remember something else you want to add, rather than post in the comments just edit your question and add it there. Thanks! – JeffC Jul 10 '16 at 23:03

0 Answers0