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
 期待你的加入;共同学习,一起进步:
python|测试|技术交流 qq群:563227894
python|测试|技术交流 qq群:563227894
python|测试|技术交流 qq群:563227894

ElementNotVisibleException: Message: element not visible的更多相关文章

  1. selenium.common.exceptions.ElementNotVisibleException: Message: element not visible处理方法:selenium针对下拉菜单事件的处理

    使用Selenium爬虫时,可能会遇到一些下拉菜单,动态加载,如果直接使用find_element_by_函数会报错,显示selenium.common.exceptions.ElementNotVi ...

  2. 爬虫-Selenium -抱错ElementNotVisibleException: Message: element not visible

    1.当使用Selenium IDE 完成了脚本的录制和回放通过后,想要将脚本转换为其他语言如java.Python等,首次使用时打开Options->Format发现没有可以转换的语言,如下: ...

  3. Firefox上运行自动化测试脚本提示元素无法点击“WebDriverException: Message: Element is not clickable at point“解决方法

    1. Firefox上运行脚本时提示“WebDriverException: Message: Element is not clickable at point (934.316650390625, ...

  4. selenium之 坑(StaleElementReferenceException: Message: Element not found in the cache...)

    今天给大家分享一个selenium中经常会有人遇到的坑: selenium.common.exceptions.StaleElementReferenceException: Message: Ele ...

  5. 两个标签页定位第二个标签页元素时显示element not visible

    问题描述 web页面有两个标签页, 当转换到第二个标签页定位元素时, 显示element not visible. 代码 ... //省略 WebElement ele= browser.getEle ...

  6. 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网站的价格计划,每一个价格计划需要三连击才能全部点开,第一个房型的价格计划是可以正确三连击打开的,可是第二个房弄就不行了,报错说不是可点击的 ...

  7. element not visible的解决方法

    抛出异常主题为element not visible主要有一下三个方面的原因. 元素之间存在逻辑关系,比如你要选择地址时,中国选择完毕之后,才能选择北京.如果想直接一步到位,则会出现element n ...

  8. 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 ...

  9. selenium之坑:点击后页面刷新重新获取刷新前的页面(StaleElementReferenceException:Message:Element not found in the cache...)

    循环点击一列链接,但只能点到第一个,第二个失败,这是为什么,因为第二个已经是新页面,当然找不到之前页面的元素,虽然元素没变,甚至是后退回来,页面都没有变,为什么是新页面,页面长的一样不代表是同一张页面 ...

随机推荐

  1. Canonical form

    https://en.wikipedia.org/wiki/Canonical_form#Linear_algebra Suppose we have some set S of objects, w ...

  2. Page8:对偶原理以及结构分解[Linear System Theory]

    内容包含状态转移矩阵的对偶性.方块图的对偶性.时序的对偶性以及对偶性原理,能控能观标准型及其结构分解

  3. [daily][centos][iptables][firewalld] firewalld的初步了解

    CentOS7中默认使用firewalld代替了iptables . 接下来将对firewalld, 做一些初步的了解. 首先读一下, redhat的文档: https://access.redhat ...

  4. Flink - ResultPartition

    发送数据一般通过,collector.collect public interface Collector<T> { /** * Emits a record. * * @param re ...

  5. 请教神牛_字符串hash

    针对字符串hash 我早就听闻可以暴力的干一些事情. 比如 可以... 很多很多 实现O(n)求出 模式串在文本串出现的次数. 但是我不会这什么hash. 我会自然溢出字符串hash 嘿嘿 unsig ...

  6. odoo10如何自定义自动生成单据编号

    1.在已有的model中穿件一个字段name class qingjiadan(models.Model): _name = 'qingjia.qingjiadan' name = fields.Ch ...

  7. mysql分库 分表

    原文链接:http://www.jianshu.com/p/89311703b320 传统的分库分表传统的分库分表都是通过应用层逻辑实现的,对于数据库层面来说,都是普通的表和库.分库分库的原因 首先, ...

  8. schtasks 命令使用

    schtasks  /create 创建任务,下面是常用参数 /tn taskname /tr taskrun /sc schedule    [Minute | Hourly | Daly | We ...

  9. 浅谈KMP算法

    一.介绍 烤馍片KMP算法是用来处理字符串匹配问题的.比如说给你两个字符串A,B,问B是不是A的子串? 比如,eg就是aeggx的子串 一般讲字符串A称为主串,用来匹配的B串称为模式串 定义n为字符串 ...

  10. Linux dmidecode 命令

    当我们需要获取机器硬件信息时,可使用linux系统自带的dmidecode工具进行查询. dmidecode 用于获取服务器的硬件信息,通常是在不打开计算机机箱的情况下使用该命令来查找硬件详细信息 这 ...