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

StaleElementReferenceException:  Message: stale element reference: element is not attached to the page document ...

出错原因为: Selenium只能操作当前打开页面中的可见元素,当页面跳转, 前进, 后退, 或刷新后, 之前定位到的元素要重新定位才能使用.

可以尝试运行以下脚本, 查看报错信息:

from selenium import webdriver

dr = webdriver.Chrome()
dr.get('http://www.baidu.com')
search = dr.find_element_by_id("kw") dr.refresh()
# search.send_keys("刷新后输入") # 报错: StaleElementReferenceException dr.get("http://www.hao123.com")
# search.send_keys("刷新后输入") # 报错: StaleElementReferenceException
dr.back()
search.send_keys("刷新后输入") # 报错: StaleElementReferenceException

Selenium报错:StaleElementReferenceException的更多相关文章

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

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

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

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

  3. selenium报错汇总

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

  4. ie11 selenium 报错org.openqa.selenium.NoSuchWindowException: Unable to get browser 处理方法

    selenium + ie11运行报错 org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The s ...

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

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

  6. python执行selenium报错

    python + unittest + HTMLTestRunner 执行suite用例报错 Traceback (most recent call last): File "C:/ws/S ...

  7. Jenkins执行selenium报错unknown error: cannot find Chrome binary

    问题描述:在Pycharm中执行selenium测试用例,可以正常运行, 集成在Jenkins中,构建时,发现构建成功,但是查看Console Output,报错:unknown error: can ...

  8. windows下使用selenium报错selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH

    问题 :执行程序代码报错: WebDriverException:Message:'geckodriver'executable needs to be in Path 或者 selenium.com ...

  9. windows使用pip安装selenium报错问题

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xb9 in position 7: ordinal not in range(128) 这是 ...

随机推荐

  1. k8s-日志收集架构

    日志收集 Kubernetes 集群中监控系统的搭建,除了对集群的监控报警之外,还有一项运维工作是非常重要的,那就是日志的收集. 介绍 应用程序和系统日志可以帮助我们了解集群内部的运行情况,日志对于我 ...

  2. Rikka with Competition hdu 6095

    签到题目,排序然后按序清理掉一定会输的结果就可以. ac代码: #include <iostream> #include <cstdio> #include <cstri ...

  3. Install CUDA 6.0 on Ubuntu 14.04 LTS

    Ubuntu 14.04 LTS is out, loads of new features have been added. Here are some procedures I followed ...

  4. DPDK latencystats库使用方案

    初始化 注意务必调用 rte_metrics_init /* init latency stats */ /* @TODO should we remove this in product env? ...

  5. BRD——>MRD——>PRD,产品经理三大文档概念详解及前后逻辑

    转自:https://blog.csdn.net/neikutaixiao/article/details/40819445 商业需求文档Business Requirement DocumentBR ...

  6. 【Struts2】防止表单重复提交

    一.概述 二.Struts2中解决方案 三.实现步骤 一.概述 regist.jsp----->RegistServlet 表单重复提交 危害: 刷票. 重复注册.带来服务器访问压力(拒绝服务) ...

  7. 【Day2】4.第三方模块的安装与使用

    课程目标 1. 使用模块 2. 安装第三方模块 使用模块 • 一个.Py文件称之为一个模块(Module) • 好处: 1. 便于代码维护,把很多函数放到不同文件,一个.py文件 的 代码数量少 2. ...

  8. Mysql(九):Python连接MySQL数据库之pymysql模块使用

    Python3连接MySQL 本文介绍Python3连接MySQL的第三方库--PyMySQL的基本使用. PyMySQL介绍 PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服 ...

  9. 多线程模块的同步机制event对象

    多线程模块的同步机制event对象 线程的核心特征就是他们能够以非确定的方式(即何时开始执行,何时被打断,何时恢复完全由操作系统来调度管理,这是用户和程序员无法确定的)独立执行的,如果程序中有其他线程 ...

  10. 修改office2019安装位置,自定义安装需要的功能

    更新:2019.5.30楼主本人本次重装系统后装office2019再次测试,没有任何问题,没认真看文章,自己胡乱一同操作,导致各种问题的,出了错就就瞎评论,说博主误导人,对你们这种人就是呵呵.左转不 ...