1

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"));
       }
      
       
       }

1 Answer 1

1

Yes I have got the solution.

  WebElement QuizTab = driver.findElement(By.xpath("//*[@id=\"page-content\"]/div/span[1]"));
    List<WebElement> tab =  QuizTab.findElements(By.tagName("button"));
    System.out.println(tab);
    System.out.println(tab.size());
    for(int i=0;i<tab.size();i++) {
        System.out.println(i);
        String tab1 = tab.get(i).getText();
        tab.get(i).click();
        Thread.sleep(1000);
                 
        // System.out.println(tab.get(i).getAttribute("data-target"));
                 
        if(tab1.equals("Import")) {
            driver.navigate().refresh();;
            }
        else{
             driver.navigate().back();
            }
                 
        Thread.sleep(1000);
        QuizTab = driver.findElement(By.xpath("//*[@id=\"page-content\"]/div/span[1]")); //*[@id="page-content"]/div/span[1]/button[5]
        tab =  QuizTab.findElements(By.tagName("button"));
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.