在使用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()

selenium报错:Message: stale element reference: element is not attached to the page document的更多相关文章

  1. appium报错Message: Cannot set the element to ‘XXXX’. Did you interact with the correct element?

    appium+python+android 在定位到模块输入内容的时候遇到了一个问题 send_keys报错 appium报错Message: Cannot set the element to 'X ...

  2. python selenium 报错unknown error: cannot focus element 解决办法

    登录框由于js限制,定位到元素后无法sendkey ,sendky报错如下: selenium.common.exceptions.WebDriverException: Message: unkno ...

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

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

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

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

  5. 报错stale element reference: element is not attached to the page document结局方案

    今天在调试脚本时,遇到如下报错: org.openqa.selenium.StaleElementReferenceException: stale element reference: elemen ...

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

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

  7. Selenium报错:StaleElementReferenceException

    一个学生在操作页面跳转时遇到一个Selenium报错, 如下图所示: StaleElementReferenceException: Message: stale element reference: ...

  8. selenium报错以及各解决方法

    1.driver.findElement(By.name("wd")).sendKeys("selenium"); 报错:The method sendKeys ...

  9. 解决centos7下 selenium报错--unknown error: DevToolsActivePort file doesn't exist

    解决centos7下 selenium报错--unknown error: DevToolsActivePort file doesn't exist 早上在linux下用selenium启动Chro ...

  10. selenium报错汇总

    selenium报错汇总 报错:[error] Could not connect to Selenium Server. Have you started the Selenium Server y ...

随机推荐

  1. 【API Management】使用 APIM Inbound Policy 来修改Content‐Type Header的值

    问题描述 在使用APIM提供API服务管理的场景中,遇见了客户端请求时候发送的请求Header中的Content-Type不满足后台服务器的要求,但是在客户端要求客户修改代码难度较高. 所以面对这样的 ...

  2. 【Azure 云服务】Azure Cloud Service中的错误事件 Error Event(Defrag/Perflib) 解答

    问题描述 在Azure Cloud Service的实例中,收集到各种 Error Event 内容,本文针对所收集的三种Event进行解析. 1: This operation is not sup ...

  3. 【Azure Developer】解答《美丽的数学》一书中P120页的一道谜题:寻找第四个阶乘和数

    一道谜题 在观看<美丽的数学>一书中,在120页中有一道谜题: 数字145被称为一个阶乘和数, 因为它具有以下有趣的属性,如果我们将它的各位数字的阶乘相加,会得到该数字本身 1! +4! ...

  4. Mysql基础目录

    尚硅谷Mysql课程笔记 课程链接: https://www.bilibili.com/video/BV1iq4y1u7vj?p=1 第01章_数据库概述 第02章_MySQL环境搭建 第03章_基本 ...

  5. 英语字母z解析.drawio

    英语字母z解析.drawio

  6. vue-router tomcat 下报404 WEB-INF 放入 web.xml 即可

    vue-router tomcat 下报404 WEB-INF 放入 web.xml 即可 <?xml version="1.0" encoding="UTF-8& ...

  7. git svn 提交代码日志填写规范 BUG NEW DEL CHG TRP gitz 日志z

    git svn 提交代码日志填写规范 BUG NEW DEL CHG TRP gitz 日志z

  8. c语言中的指针,数组和结构体结合的一个经典案例

    一 你真正懂了C语言了吗? 很多人刚把c语言用了两年,就以为很懂,等遇到稍微深层次一点的问题,就卡住了.这里,有一个问题,可以考察你对这三者理解如何. 二 一个例子: #include <std ...

  9. 使用JdbcTemplate

    1.使用JdbcTemplate的execute()方法执行SQL语句 Java代码  收藏代码 jdbcTemplate.execute("CREATE TABLE USER (user_ ...

  10. ffmpeg播放器-音视频解码流程

    目录 音视频介绍 音视频解码流程 FFmpeg解码的数据结构说明 AVFormatContext数据结构说明 AVInputFormat数据结构说明 AVStream数据结构说明 AVCodecCon ...