I am creating script for list but it is all four tab run and when last tab found it's popup it automatically script fails. How to put condition if it is continuously run. Please see my code. http://prntscr.com/10pp6a5
WebElement QuizTab = driver.findElement(By.xpath("//*[@id="page-content"]/div/span[1]"));
List tab = QuizTab.findElements(By.tagName("button"));
System.out.println(tab.size());
for(int i=0;i<tab.size();i++) {
System.out.println(tab.get(i).getText());
tab.get(i).click();
Thread.sleep(1000);
driver.navigate().back();
Thread.sleep(1000);
//if(button.equals(i)) {
if(tab.get(i).getAttribute("data-toggle").equalsIgnoreCase("modal")){
driver.findElement(By.linkText("Cancel")).click();
System.out.println("the system will be continue run");
}else {
QuizTab = driver.findElement(By.xpath("//*[@id=\"page-content\"]/div/span[1]"));
tab = QuizTab.findElements(By.tagName("button"));
}
}