今天在调试脚本时,遇到如下报错:

org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document

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

下面说下我的情况:

我进入页面dom结构,查看发现原来table表格的id实时自增,即id=id++;这种模式,坑死了,加上度娘找的自己理解,终于解决了该问题解决方案如下:

  1. 因为是动态id,也就是说实时刷新,因此采取相对路径定位, xpath加and锁定定位条件,建议至少两个约束。
  2. 进到列表页时,先执行refresh方法,在获取到当前列集合,在去操作想要操作元素即可。

报错stale element reference: element is not attached to the page document结局方案的更多相关文章

  1. 关于报错stale element reference: element is not attached to the page document处理

    1.现象 在执行脚本时,有时候引用一些元素对象会抛出如下异常 org.openqa.selenium.StaleElementReferenceException: stale element ref ...

  2. selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document

    抓取网页代码后,由于是在同一个li标签下,所以使用一次性抓取,所有的a标签,然后循环做不同的操作,但是抛出找不到元素异常. def office_page(_chrome: Chrome): sn = ...

  3. mybatis项目启动报错 The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".

    启动项目报错 2018-02-26 17:09:51,535 ERROR [org.springframework.web.context.ContextLoader] - Context initi ...

  4. 关于xpath语句完全正确,但是页面报错: no such element: Unable to locate element: {"method":"xpath","selector":"xpath"}

    之前使用selenium-webdriver来写UI的自动化脚本,发现有一个元素一直无法定位,查看其源码,如下 利用xpathChecker验证了xpath语句的是正确的,但是控制台一直报错: no ...

  5. stale element reference: element is not attached to the page document 异常

    在执行脚本时,有时候引用一些元素对象会抛出如下异常 org.openqa.selenium.StaleElementReferenceException: stale element referenc ...

  6. java报错:The reference to entity "characterEncoding" must end with the ';' delimiter.

    java关于报错:The reference to entity "characterEncoding" must end with the ';' delimiter. Java ...

  7. 【问题记录】element is not attached to the page document

    遇到ui脚本报错:element is not attached to the page document 解决办法,再次定位即可

  8. 记录微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function

    微信小程序报错 Unexpected end of JSON input;at pages/flow/checkout page getOrderData function 这个报错是在将数组对象通过 ...

  9. Selenium2学习-012-WebUI自动化实战实例-010-解决元素失效:StaleElementReferenceException: stale element reference: element is not attached to the page document

    元素失效的想象提示信息如下图所示,此种问题通常是因为元素页面刷新之后,为重新获取元素导致的. 解决此类问题比较简单,只需要在页面刷新之后,重新获取一下元素,就可以消除此种错误了. 以下以易迅网搜索为例 ...

随机推荐

  1. 第十一周(11.24-12.01)----ptim测试程序运行速度

    我在dos下用ptime指令对分数运算(http://www.cnblogs.com/YangXiaomoo/p/6095583.html)的运行时间进行了测试.测试结果一般都在0.212-0.217 ...

  2. [转载] 什么是istio 官网内容

    网址:https://preliminary.istio.io/zh/docs/concepts/what-is-istio/ mark 一下 1.0 昨天刚发布. 2018.7.31 Istio 是 ...

  3. javascript extend

    interface Date{ addHours(h:number); addMinutes(m:number); format(str):string } interface String{ tri ...

  4. SQL 优化经验总结34条

    我们要做到不但会写SQL,还要做到写出性能优良的SQL,以下为笔者学习.摘录.并汇总部分资料与大家分享!   (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析器按照 ...

  5. bzoj 3531 [Sdoi2014]旅行 (树剖+线段树 动态开点)

    3531: [Sdoi2014]旅行 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 2984  Solved: 1312[Submit][Status ...

  6. 【题解】 luogu 3857 [TJOI2008]彩灯 (线性基)

    luogu3857,懒得复制 Solution: 裸的线性基,往里面添加数,记录添加个数\(sum\),快速幂输出\(2^{sum}\)即可 Code: //It is coded by Ning_M ...

  7. debian9部署jenkins

    这里记录两种部署方式,一种是通过包管理工具直接安装,另一种是用tomcat作为web容器运行jenkins.个人倾向第一种,部署简单,而且维护起来方便很多. 用包管理工具aptitude部署jenki ...

  8. 洛谷P4211 LCA

    题意:多次询问,每次求点的标号在[l, r]之间的所有点到点z的lca的深度. 解:看到这题有没有想到某一道很熟悉的题?紫妹和幽香是17岁的少女,喜欢可爱的东西...... 显然这就是开店的超级无敌弱 ...

  9. oracle递归查询(查询条件ID下得所有子集)

    一.CREATE TABLE TBL_TEST ( ID    NUMBER, NAME  VARCHAR2(100 BYTE), PID   NUMBER                       ...

  10. Oracle表字段类型更改的一个经验

    先前表中ID字段类型是用序列,由于安全问题,需要处理水平权限的漏洞,虽然使用加密也可以处理,为了更方便,需要将字段类型改为Guid,如果表中已经有数据,更改起来不是很方便,对于基础数据表,这里提供一个 ...