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!