How to handle StaleElementReferenceException

前端 未结 2 1000
谎友^
谎友^ 2021-01-28 02:35

I am working for a mouse hover and i want to test all the links working condition by clicking each and every link using for loop.In my program the iteration is going once and fo

2条回答
  •  余生分开走
    2021-01-28 03:13

    You can use following modification in your code:-

     List  links=driver.findElements(By.xpath("//a[contains(@class,'sf-depth-2')]"));
    
           for(int i=0;i  allLinks=driver.findElements(By.xpath("//a[contains(@class,'sf-depth-2')]"));
               allLinks.get(i).click();
    
            driver.navigate().back();
    
               }
    

提交回复
热议问题