【问题标题】:Looping through with List<WebElement> with Selenium使用 Selenium 循环使用 List<WebElement>
【发布时间】:2016-12-31 06:22:24
【问题描述】:

我使用下面的代码获得了一个锚点列表,然后我想转到每个链接。我想出了下面的代码,但是在第一个循环之后,我得到了以下异常

org.openqa.selenium.StaleElementReferenceException:过时的元素 参考:元素未附加到页面文档(会话 信息:铬=55.0.2883.87)

List<WebElement> listingAnchorList = driver.findElements(By.xpath("//div[contains(@class,'cat')]/a"));

for (WebElement listingAnchor : listingAnchorList) {
    driver.get(listingAnchor.getAttribute("href"));
    System.out.println(driver.getTitle());
}

有没有办法做到这一点而不必每次都返回页面?

【问题讨论】:

    标签: java selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    您可以在一些新的List 中收集您的href 属性,然后对其进行迭代并打开每个页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      • 2013-06-09
      • 1970-01-01
      相关资源
      最近更新 更多