背景: 用WebDriverWait时,一开始用的是presence_of_element_located,我对它的想法就是他就是用来等待元素出现。结果屡屡出问题。元素默认是隐藏的,导致等待过早的就结束了。

解决:去StackOverFlow查了一下,发现我应该用visibility_of_element_located。

http://stackoverflow.com/questions/19675696/performance-of-visibilityofelementlocated-v-s-presenceofelementlocated-selenium

原文:

Well, I would guess that presenceOfElementLocated will be slighty faster because it's just check elements presence on the page while the visibilityOfElementLocated has to check the presenceand whether is element visible.

But I think it really doesn't matter from the performance perspective (what's the point if you save 0.001 second during this checking?), you better choose appropriate method depending on your use case.

  • use presenceOfElementLocated when you don't care whether if element visible or not, you just need to know if it's on the page
  • use visibilityOfElementLocated when you need to find element which should be also visible

Look at the documentation for more info.

翻译:

我猜 presence_of_element_located 肯定会稍微快一点,因为它仅仅检查了页面是否存在该元素,而visibility_of_element_located还必须检查元素是否存在以及元素是否可见。

但是我认为从性能角度考虑,确实没啥影响。最好根据使用情况来选择正确的方法。

  • presence_of_element_located: 当我们不关心元素是否可见,只关心元素是否存在在页面中。
  • visibility_of_element_located: 当我们需要找到元素,并且该元素也可见。

selenium python presence_of_element_located vs visibility_of_element_located的更多相关文章

  1. <译>Selenium Python Bindings 5 - Waits

    如今,大多数的Web应用程序使用AJAX技术.当页面加载到浏览器,页面中的元素也许在不同的时间间隔内加载.这使得元素很难定位,如果在DOM中的元素没有呈现,它将抛出ElementNotVisibleE ...

  2. [译]Selenium Python文档:五、Waits等待

    大多数现代web应用都使用了AJAX技术.当浏览器加载一个页面的时候,该页面内的元素可能在不用的时间间隔内进行加载.这使得元素定位变得比较困难:如果一个元素还没有出现在DOM中,定位函数将会抛出一个E ...

  3. selenium+python : Waits---study

    from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.s ...

  4. <译>Selenium Python Bindings 6 - WebDriver API

    本章涉及Selenium WebDriver的所有接口. Recommended Import Style 推荐的导入风格如下: from selenium import webdriver 然后,你 ...

  5. presence_of_element_located对比visibility_of_element_located

    presence_of_element_located和visibility_of_element_located都是selenium里判断元素展示的方法,相信做ui自动化的小伙伴一定被这俩困扰过,本 ...

  6. selenium + python自动化测试环境搭建

    selenium的在python平台的搭建: 搭建平台windows 准备工具如下: --------------------------------------------------------- ...

  7. Page Object Model (Selenium, Python)

    时间 2015-06-15 00:11:56  Qxf2 blog 原文  http://qxf2.com/blog/page-object-model-selenium-python/ 主题 Sel ...

  8. selenium + python 多浏览器测试

    selenium + python 多浏览器测试 支持库包 在学习 Python + Selenium 正篇之前,先来看下对多浏览器模拟的支持.目前selenium包中已包含webdriver,hel ...

  9. selenium + python 自动化测试环境搭建

    selenium + python 自动化测试 —— 环境搭建 关于 selenium Selenium 是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操 ...

随机推荐

  1. Missing artifact com.sun:tools:jar:1.5.0

    http://java-suddy.iteye.com/blog/1821871(解决了我的问题)

  2. Linux中的find指令

    find find是最常见和最强大的查找命令,在磁盘中查找文件,用它找到任何你想找的文件,就是速度有点慢. find    path    -option    [    -print ]    [ ...

  3. Cocos2dx开发(1)——Win8.1下 NDK r10 环境搭建

    内容简要:仅讲述NDK在Windows环境下搭建方法,至于NDK何物一概不属于本文内容,老鸟或已有环境的跳过. 笔者已安装的环境: vs2013企业版.谷歌官网adt 22.3.0(推荐)省得自己ec ...

  4. Vim简明教程【CoolShell】

    vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim Progress ...

  5. 在CentOS 6.3中安装与配置JDK-7

    在CentOS 6.3中安装与配置JDK-7 来源:互联网 作者:佚名 时间:02-07 16:28:33 [大 中 小] 在CentOS-6.3中安装与配置JDK-7,有需要的朋友可以参考下 安装说 ...

  6. WIN7下运行hadoop程序报:Failed to locate the winutils binary in the hadoop binary path

    之前在mac上调试hadoop程序(mac之前配置过hadoop环境)一直都是正常的.因为工作需要,需要在windows上先调试该程序,然后再转到linux下.程序运行的过程中,报Failed to ...

  7. Unity3D动态加载外部资源

    最近一直在和这些内容纠缠,把心得和大家共享一下: Unity里有两种动态加载机制:一是Resources.Load,一是通过AssetBundle,其实两者本质上我理解没有什么区别.Resources ...

  8. Bootstrap_Javascript_固定定位

    Affix 插件可以对任何元素进行固定定位,其中比较简单的方法,就是通过自定义属性 data 来触发.其主要包括两个参数: 1.data-spy:取值 affix,表示元素固定不变的. 2.data- ...

  9. 浅谈Chrome V8引擎中的垃圾回收机制

    垃圾回收器 JavaScript的垃圾回收器 JavaScript使用垃圾回收机制来自动管理内存.垃圾回收是一把双刃剑,其好处是可以大幅简化程序的内存管理代码,降低程序员的负担,减少因 长时间运转而带 ...

  10. Android Application的使用及其生命周期

    摘要: 1. Application的使用 2. Application的生命周期 ---------------------------------------------------- 工程代码: ...