一个学生在操作页面跳转时遇到一个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. Python 正则表达模块详解

    Python 的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承.Py ...

  2. OSG3.4内置Examples解析【目录】

    opengl渲染管线 从整体上解读OpenGL的渲染流程 一 从整体上解读OpenGL的渲染流程 二 osg与animate相关示例解析 OSG3.4内置Examples(osganimate)解析 ...

  3. 基于C#实现与新大陆扫码枪通信

    随着工业互联的发展,扫码枪在很多场合都有所应用,超市.商场以及一些智能工厂.今天主要讲如何通过C#实现与新大陆扫码枪(OY10)进行通信,对于扫码枪的配置,这里就不多说了,结合说明书就可以实现.这里值 ...

  4. JAVA中ArrayList重写比较方法

    ArrayList的sort方法重写: 当ArrayList中存放的为含有多个成员变量的数据类型时,在进行sort排序时要重写比较方法,一般都写在这个数据类型类的内部如: package 算法竞赛入门 ...

  5. 使用Vue CLI脚手架搭建vue项目

    本次是使用@vue/cli 3.11.0版本搭建的vue项目 1. 首先确保自己的电脑上的Node.js的版本是8.9版本或者以上 2. 全局安装vue/cli npm install @vue/cl ...

  6. JAVA栅栏和闭锁的区别

    闭锁:一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.即,一组线程等待某一事件发生,事件没有发生前,所有线程将阻塞等待:而事件发生后,所有线程将开始执行:闭锁最初 ...

  7. 网页接入dingding扫码登录

    前言 有时候我们做了一些网页,希望只有某些人才能看的话,可以搞一个钉钉扫码登录,接入也比较简单,下面记录下接入的过程. 流程 我们先看看官方的文档:钉钉接入文档梳理一下官方的流程:1.先跳去一个扫码网 ...

  8. aop 的一些表达式

    切入点的表达式 execution(void cn.itcast.e_xml.a_before.UserServiceImpl.saveUser(java.lang.String,java.lang. ...

  9. c++实现单向链表的一些操作

    #include<iostream> #include <algorithm> #include <vector> #include <set> #in ...

  10. Django_04_视图

    视图 后台管理页面做好了,接下来就要做公共访问的页面了 对于django的设计框架MVT,用户在URL中请求的是视图,视图接收请求后进行处理,并将处理的结果返回给请求者 使用视图时需要进行两步操作 1 ...