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...)
循环点击一列链接,但只能点到第一个,第二个失败,这是为什么,因为第二个已经是新页面,当然找不到之前页面的元素,虽然元素没变,甚至是后退回来,页面都没有变,为什么是新页面,页面长的一样不代表是同一张页面 ...
随机推荐
- 利用win10自带的虚拟机Hyper-V安装Centos7的步骤教程
1.设置开启Hyper-V应用程序? 在搜索功能里输入 Hyper-V 然后点击选中的部分 2.全部选中框中的部分,然后重新启动电脑 3.在搜索功能里输入Hyper-V 打开 4.点击新建--> ...
- 用pymysql操作MySQL数据库
工具库安装 pip install pymysql 连接关闭数据库与增删改查操作 # 导入pymysql库 import pymysql # 打开数据库连接 # 参数1:数据库服务器所在的主机+端口号 ...
- Srt字幕文件解析
// // ViewController.m // 字幕解析 // // Created by admin on 2018/8/30. // Copyright © 2018年 admin. All ...
- PHP之二维数组根据某个下标排序
function arraySortByElements($array2sort,$sortField,$order,$iscount=false) { $functionString=' if (' ...
- go install and go captcha
https://blog.csdn.net/liuhongwei123888/article/details/8512815 [gocaptcha] http://www.cnblogs.co ...
- python知识点杂记2
1. 如果已经有一个list或者tuple,要调用一个可变参数怎么办?2. >>> nums = [1, 2, 3]3. >>> calc(*nums)4. 14* ...
- 转:Java 异常结构体系
原文地址:Java 异常结构体系 保存一份资料 前几天在参加网易和360公司的在线考试的时候,都出了一道关于java中异常类的多项选择题.这几天翻看了相关书籍和网上一些资料,结合自己的理解与思考,将自 ...
- vue关于html页面id设置问题
vue是一个前端框架,类似于angularJS等,vue在编写的时候需要在html页面指定id,但是不是都可以实现的,一般放在id需在div设置里才可以实现. (一) 在html里设置id: < ...
- Python中的下划线(转)
译文原文:https://segmentfault.com/a/1190000002611411 原文地址这篇文章讨论Python中下划线_的使用.跟Python中很多用法类似,下划线_的不同用法绝大 ...
- 关于eclipse调试时程序控制台不能自动打开
对于这个程序,在刚开始的时候,没有敲上22,29,33行的打印语句时,在调试的时候不会自动弹开控制台,所以一直在怀疑代码可能出错了.因此可以自己手动打开,但是如果敲上那些代码,系统可以自动弹开控制 ...