stale element reference: element is not attached to the page document
来源:互联网 发布:微信for windows和uwp 编辑:程序博客网 时间:2024/05/20 11:24
报错原因:
由于页面刷新后,需要重新定位元素
解决方案:try-catch
报错前的代码:
WebElement element=driver.findElement(By.xpath("//input[@id='name']")); element.sendKeys("输入的文本");
解决后的代码:
try { WebElement element=driver.findElement(By.xpath("//input[@id='name']")); element.sendKeys("输入的文本"); } catch(org.openqa.selenium.StaleElementReferenceException ex) { WebElement element=driver.findElement(By.xpath("//input[@id='name']")); element.sendKeys("输入的文本"); }
注意:catch()内和常见的区别,这里的是:org.openqa.selenium.StaleElementReferenceException ex
总结:
1.try-catch相当于在页面刷新后再次获取一次元素,即在try中判断找不到元素时,执行catch中代码再次加载一次元素2.注意catch括号中的代码,和平常的catch不太一样
阅读全文
0 0
- stale element reference: element is not attached to the page document
- selenium2.0报错:stale element reference: element is not attached to the page document的解决办法
- Selenium element is not attached to the page document
- Stale Element Reference Exception
- How a DOM Element is Attached
- could not be added to the element
- 关于xml配置文件无元素提示和the root element of the document is not <xsd:schema>.错误
- Note: This element has no attached Javadoc and the Javadoc could not be found in the attached source
- Note:This element has no attached source and the javadoc could not be found in the attached javadoc
- Note: This element has no attached source and Javadoc could not be found in the attached Javadoc解决办法
- 关于DOM element with id in Element cache is not the same as element in the Dom解决方法
- source not found-Note:This element has not attached解决办法
- The prefix "tx" for element "tx:advice" is not bound.
- The prefix "tx" for element "tx:advice" is not bound
- javascript错误解决:Unable to modify the parent container element before the child element is closed
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed
- IE8报错:Unable to modify the parent container element before the child element is closed
- HTML Parsing Error:Unable to modify the parent container element before the child element is closed
- 转换编码 u'```'
- 前端框架对比——PC Web端电脑端前端框架用哪个好——前端最新最热框架对比
- selenium访问下拉列表
- 【Scikit-Learn 中文文档】成对的矩阵, 类别和核函数
- springboot 配合 profile 多环境自动切换配置文件
- stale element reference: element is not attached to the page document
- jetson tk1安装cuda toolkit的错误
- Reference counted Objects (引用计数对象)
- jprofile 监控resin关键配置过程
- Android ContentProvider实例详解
- SecureCRT和SecureFx设置中文乱码
- SpringBoot入门系列:第五篇 JPA mysql
- 在linux下启动resin
- java实现附件预览(openoffice+swftools+flexpaper)