ElementNotVisibleException: Message: element not visible
selenium自动化测试中,经常会报异常:
可能会有各种疑问,元素可以定位到啊。为什么报以下异常?
ElementNotVisibleException: Message: element not visible
原因:
元素在前台代码document中可以找到,但是不代表该元素就显示在了页面上。
所以报上述异常的原因就是,元素未显示在界面上。
能过我们测试中会自定义一下,找元素的功能:
def find_element(self,*loc):
"""
在指定时间内,查找元素;否则抛出异常
:param loc: 定位器
:return: 元素 或 抛出异常
"""
TimeOut = 20
try:
self.driver.implicitly_wait(TimeOut) #智能等待;超时设置 element = self.driver.find_element(*loc) #如果element没有找到,到此处会开始等待
if self.isDisplayTimeOut(element,TimeOut):
self.hightlight(element) #高亮显示
else:
raise ElementNotVisibleException #抛出异常,给except捕获 self.driver.implicitly_wait(0) #恢复超时设置
return element except (NoSuchElementException,ElementNotVisibleException,UnexpectedAlertPresentException) as ex:
self.getImage
raise ex
判断元素是否在页面显示:
def isDisplayTimeOut(self,element,timeSes):
"""
在指定时间内,轮询元素是否显示
:param element: 元素对象
:param timeSes: 轮询时间
:return: bool
"""
start_time = int(time.time()) #秒级时间戳
timeStr = int(timeSes)
while (int(time.time())-start_time) <= timeSes:
if element.is_displayed():
return True
self.wait(500) self.getImage
return False
ElementNotVisibleException: Message: element not visible的更多相关文章
- selenium.common.exceptions.ElementNotVisibleException: Message: element not visible处理方法:selenium针对下拉菜单事件的处理
使用Selenium爬虫时,可能会遇到一些下拉菜单,动态加载,如果直接使用find_element_by_函数会报错,显示selenium.common.exceptions.ElementNotVi ...
- 爬虫-Selenium -抱错ElementNotVisibleException: Message: element not visible
1.当使用Selenium IDE 完成了脚本的录制和回放通过后,想要将脚本转换为其他语言如java.Python等,首次使用时打开Options->Format发现没有可以转换的语言,如下: ...
- Firefox上运行自动化测试脚本提示元素无法点击“WebDriverException: Message: Element is not clickable at point“解决方法
1. Firefox上运行脚本时提示“WebDriverException: Message: Element is not clickable at point (934.316650390625, ...
- selenium之 坑(StaleElementReferenceException: Message: Element not found in the cache...)
今天给大家分享一个selenium中经常会有人遇到的坑: selenium.common.exceptions.StaleElementReferenceException: Message: Ele ...
- 两个标签页定位第二个标签页元素时显示element not visible
问题描述 web页面有两个标签页, 当转换到第二个标签页定位元素时, 显示element not visible. 代码 ... //省略 WebElement ele= browser.getEle ...
- python+selenium:点击页面元素时报错:WebDriverException: Message: Element is not clickable at point (1372.5, 9.5). Other element would receive the click: <li style="display: list-item;" id="tuanbox"></li>
遇到一个非常郁闷的问题,终于解决了, 问题是这样的,NN网站的价格计划,每一个价格计划需要三连击才能全部点开,第一个房型的价格计划是可以正确三连击打开的,可是第二个房弄就不行了,报错说不是可点击的 ...
- element not visible的解决方法
抛出异常主题为element not visible主要有一下三个方面的原因. 元素之间存在逻辑关系,比如你要选择地址时,中国选择完毕之后,才能选择北京.如果想直接一步到位,则会出现element n ...
- python + web自动化,点击不生效,提示“selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (117, 674)”
前言: 在做web自动化时,遇到一个缩放了浏览器比例的操作,从100%缩小到80%,再进行点击的时候,弹出报错信息,无法点击 selenium.common.exceptions.ElementCli ...
- selenium之坑:点击后页面刷新重新获取刷新前的页面(StaleElementReferenceException:Message:Element not found in the cache...)
循环点击一列链接,但只能点到第一个,第二个失败,这是为什么,因为第二个已经是新页面,当然找不到之前页面的元素,虽然元素没变,甚至是后退回来,页面都没有变,为什么是新页面,页面长的一样不代表是同一张页面 ...
随机推荐
- centos 下部署django nginx+uwsgi
为了建立一个工作站,也是麻烦了.... 感谢该博主: https://www.cnblogs.com/levelksk/p/7921066.html 1.安装centos 后首先安装python,下载 ...
- 20165311学习基础和C语言基础调查
一.技能学习经验 有什么技能比90%的人更好? 这个问题问的就很emmmm..我觉得自己的推理和逻辑思维能力比较出众,面对新事物的自学速度比较快. 针对技能谈一下成功的经验. 每一项出众的技能都是与平 ...
- [No0000147]深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing)理解堆与栈4/4
前言 虽然在.Net Framework 中我们不必考虑内在管理和垃圾回收(GC),但是为了优化应用程序性能我们始终需要了解内存管理和垃圾回收(GC).另外,了解内存管理可以帮助我们理解在每一个程 ...
- Python:导入自定义模块
在C语言里为了工程文件的主程序main代码简洁的效果,我们经常用include“XXX”的来导入其.h文件 在Python里Import自己的自定义模块需要注意几个坑 以main主函数和需要导入的ha ...
- arcgis10.4 server第一次发布地图报错:We were unable to connect to...Error:Proxy server got bad address...
arcgis 10.4发布地图跟10.2不一样.server url里的http要改为https,否则就会连接不上.
- golang的json数据解析
import ( "fmt" "time" "github.com/astaxie/beego" " ...
- for in 循环
for in循环可以循环遍历数组 关键也可以循环遍历对象!而一般的for循环只能循环遍历数组, 当循环遍历对象时key值代表键值对的键,obj[key]则是对应键的值: 当循环遍历数组时,数组不是 ...
- DevExpress换肤
procedure TForm1.cxComboBox1PropertiesChange(Sender: TObject); begin // 这个地方必须是UserSkin,不然不会起作用 dxSk ...
- NYOJ 布线问题
#include<iostream> #include<stdio.h> #include<queue> #include<algorithm> usi ...
- vue-电脑端导出-txt
// fakeClick(obj) { // var ev = document.createEvent("MouseEvents"); // ev.initMouseEvent( ...