0
try {
    List<WebElement> list1 = driver.findElements(By.tagName("a"));

    for (WebElement e : list1) {
        if (e.getAttribute("href").equalsIgnoreCase("/ProductsRoute.do")) {
            if (driver.findElement(By.id("buttonCheck++Check")).isDisplayed()) {
                driver.findElement(By.id("buttonCheck++Check")).click();
                ProductConfPageexceptionHandler(driver);
                break;
            }
        else if (driver.findElement(By.name("Next")).isDisplayed()) {
                WebElement nextBut = driver.findElement(By.name("Next"));
                nextBut.click();
                break;
            }
        break; 
        }   
}
    }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

The problem is that, when the script executes e.getAttribute("href"), it looks for /ProductsRoute.do. If it does not find it, then it should break there. But the issue is that I'm getting java.lang.NullPointerException.

The expectation is that, it should find try to find the href /Products.do, if it is not there, it should break there. if it's in /Product.do, then it should execute the next if. Need you help in finding the issue. Thanks guys!

Lee
  • 738
  • 3
  • 13
Mathan
  • 162
  • 1
  • 2
  • 14

1 Answers1

1

Possible solutions for this:

  1. To check List size and make sure that elements are present

    assertThat(list1.size() >0).isTrue()

  2. Give some wait time before if condition

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Ranjith's
  • 4,508
  • 5
  • 24
  • 40