zoukankan      html  css  js  c++  java
  • selenium报错:Message: stale element reference: element is not attached to the page document

    在使用selenium时,报了一个错误

    报错的原因:

      所引用的元素已过时,不再依附于当前页面。通常情况下,这是因为页面进行了刷新或跳转

    解决方法:

      重新定位元素

    代码示例:

    # 旧代码(报错)
    lists = self.root.find_elements_by_xpath('/html/body/table[4]/tbody/tr[2]/td/a')
    for i in lists:
        self.root.get(i.get_attribute(''href))
    # 新代码(解决方法)
    lists = self.root.find_elements_by_xpath('/html/body/table[4]/tbody/tr[2]/td/a')
    for j in range(len(lists)):
        self.root.find_elements_by_xpath('/html/body/table[4]/tbody/tr[2]/td/a')[j].click()
  • 相关阅读:
    945.使数组唯一的最小增量
    用两个栈实现队列
    MySQL的约束
    数据库的设计
    约束
    DQL查询
    数据库的基本概念
    SQL基础语法
    MySQL基础
    java的注解和反射
  • 原文地址:https://www.cnblogs.com/shiyixirui/p/13863060.html
Copyright © 2011-2022 走看看