Selenium报错:StaleElementReferenceException
一个学生在操作页面跳转时遇到一个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的更多相关文章
- 解决centos7下 selenium报错--unknown error: DevToolsActivePort file doesn't exist
解决centos7下 selenium报错--unknown error: DevToolsActivePort file doesn't exist 早上在linux下用selenium启动Chro ...
- selenium报错以及各解决方法
1.driver.findElement(By.name("wd")).sendKeys("selenium"); 报错:The method sendKeys ...
- selenium报错汇总
selenium报错汇总 报错:[error] Could not connect to Selenium Server. Have you started the Selenium Server y ...
- ie11 selenium 报错org.openqa.selenium.NoSuchWindowException: Unable to get browser 处理方法
selenium + ie11运行报错 org.openqa.selenium.NoSuchWindowException: Unable to get browser (WARNING: The s ...
- python selenium 报错unknown error: cannot focus element 解决办法
登录框由于js限制,定位到元素后无法sendkey ,sendky报错如下: selenium.common.exceptions.WebDriverException: Message: unkno ...
- python执行selenium报错
python + unittest + HTMLTestRunner 执行suite用例报错 Traceback (most recent call last): File "C:/ws/S ...
- Jenkins执行selenium报错unknown error: cannot find Chrome binary
问题描述:在Pycharm中执行selenium测试用例,可以正常运行, 集成在Jenkins中,构建时,发现构建成功,但是查看Console Output,报错:unknown error: can ...
- 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 ...
- windows使用pip安装selenium报错问题
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb9 in position 7: ordinal not in range(128) 这是 ...
随机推荐
- 17.tmux相关
Linux终端复用神器-Tmux使用梳理 Tmux是一个优秀的终端复用软件,类似GNU Screen,但来自于OpenBSD,采用BSD授权.使用它最直观的好处就是,通过一个终端登录远程主机并运行tm ...
- Memcache与Redis有什么区别?
Redis 和 Memcache 都是基于内存的数据存储系统.Memcached是高性能分布式内存缓存服务,其本质上就是一个内存key-value数据库.Redis是一个开源的key-value存储系 ...
- 怎样使当前cookie只有在加密协议https环境下才能将它发送到服务器
使用 Secure 属性. 注意, 这个属性基本是"自动"的, 也就是说, 如果当前网页是https请求的, 那里面的各种HTTP请求的cookie都会自定加上这个属性, 如果当前 ...
- WebApi 空项目生成帮助文档
1.创建一个WebApi的空项目 2.写一些接口,在接口文档中忽略某个方法可以使用 [ApiExplorerSettings(IgnoreApi = true)] 特性 3.在Nuget中添加 Mi ...
- 客户端相关知识学习(十)之app给h5传递数据
方法一: app可以把参数传到h5的链接里,用类似?xx=xx&xx=xx的形式拼接,js解析参数即可. 方法二: 情况一:app调用h5 原生app都可以对js的function进行触发,前 ...
- Springboot+mybatis+druid 配置多数据源
项目结构 application.yml配置文件 spring: application: name: service datasource: primary: jdbc-url: jdbc:orac ...
- 关于windows下编写的shell脚本在linux下无法运行报错问题
首先,你写的shell脚本必须是正确的, 其次,无法运行的原因:因为windows下的换行是两个字节,而你上传到linux,linux下换行是两个字节,所以编译的酒不正确的,导致无法 运行脚本, 这种 ...
- api校验
服务端代码: import hashlib import time KEY = 'RTYUIFGHJKVBNM' def gen_key(ctime): md5 = hashlib.md5() key ...
- easyui的combobox默认选中第一个选项
pmProjectSelect.combobox({ editable:false, width:165, url : ctx + '/PmProject/findByProjectMgr', //c ...
- redis cluster(集群)模式的创建方式
redis常用的架构有三种,单例.哨兵.集群,其他的都说过了,这里只简单介绍集群搭建. 单例最简单没什么好说的. 哨兵之前说过,该模式下有哨兵节点监视master和slave,若master宕机可自动 ...