StaleElementReferenceException
当我尝试单击循环中的元素时,我收到了。以下是代码:
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to("URL");
WebElement Links=driver.findElement(By.xpath("//*[@id='chromemenu']"));
List <WebElement> AllLinks=Links.findElements(By.tagName("a"));
System.out.println(AllLinks.size());
//String start_xpath="//*[@id='chromemenu']/ul/li[";
//String end_xpath="]/a";
for(int i=1;i<AllLinks.size();i++)
{
System.out.println(AllLinks.get(i).getText());
System.out.println(AllLinks.get(i).getAttribute("href"));
//AllLinks.get(i).click();
//This is where i am clicking approach 1
//driver.findElement(By.xpath(start_xpath+i+end_xpath)).click();
//This is where i am clicking approach 2
//driver.navigate().back();
}