from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()

  This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return is for ExpectedCondition type is Boolean return true or not null return value for all other ExpectedCondition types.

Expected Conditions

There are some common conditions that are frequent when automating web browsers. Listed below are Implementations of each. Selenium Python binding provides some convienence methods so you don’t have to code an expected_condition class yourself or create your own utility package for them.

  • title_is
  • title_contains
  • presence_of_element_located
  • visibility_of_element_located
  • visibility_of
  • presence_of_all_elements_located
  • text_to_be_present_in_element
  • text_to_be_present_in_element_value
  • frame_to_be_available_and_switch_to_it
  • invisibility_of_element_located
  • element_to_be_clickable - it is Displayed and Enabled.
  • staleness_of
  • element_to_be_selected
  • element_located_to_be_selected
  • element_selection_state_to_be
  • element_located_selection_state_to_be
  • alert_is_present
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, )
element = wait.until(EC.element_to_be_clickable((By.ID,'someid')))

Implicit Waits

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.

from selenium import webdriver

driver = webdriver.Firefox()
driver.implicitly_wait() # seconds
driver.get("http://somedomain/url_that_delays_loading")
myDynamicElement = driver.find_element_by_id("myDynamicElement")

selenium+python : Waits---study的更多相关文章

  1. <译>Selenium Python Bindings 5 - Waits

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

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

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

  3. [译]Selenium Python文档:目录

    作者:Baiju Muthukadan 协议:本文档采用知识共享署名 - 共享4.0国际许可. 原英文网址:http://selenium-python.readthedocs.io/index.ht ...

  4. selenium + python自动化测试unittest框架学习(五)webdriver的二次封装

    因为webdriver的api方法很长,再加上大多数的定位方式是以xpath方式定位,更加让代码看起来超级长,为了使整体的代码看起来整洁,对webdriver进行封装,学习资料来源于虫师的<se ...

  5. selenium + python自动化测试unittest框架学习(二)

    1.unittest单元测试框架文件结构 unittest是python单元测试框架之一,unittest测试框架的主要文件结构: File >report >all_case.py &g ...

  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. JSON学习资料整理

    1.什么是JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使 ...

  2. [置顶] Java中字符串为什么不以\0结尾

    其实这个问题没有什么好说的,Java里面一切都是对象,是对象的话,字符串肯定就有长度,即然有长度,编译器就可以确定要输出的字符个数,当然也就没有必要去浪费那1字节的空间用以标明字符串的结束了. 学过C ...

  3. Mac 显示和隐藏文件

    显示和隐藏文件 显示Mac隐藏文件的命令: defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏Mac隐藏文件的命令: def ...

  4. textarea光标移到末尾兼容ie,ffchrome

    function moveEnd(obj){         obj.focus();         var len = obj.value.length;         if (document ...

  5. java基础-类变量,类方法

  6. MISRA-C 2012 Amendment 1

  7. posix_memalign详细解释(转)——自定义对齐大小的内存分配函数

    转载:http://hi.baidu.com/freelonely/blog/item/340341077c4d287302088189.html 预对齐内存的分配 在大多数情况下,编译器和C库透明地 ...

  8. spring mysql多数据源配置

    spring mysql多数据源配置 @Configuration public class QuartzConfig { @Autowired private AutowireJobFactory ...

  9. servlet常用操作

      servlet常用操作 CreateTime--2017年9月7日09:36:43 Author:Marydon 1.获取当前应用程序对象 需要导入: import javax.servlet.S ...

  10. exception 值太大

      CreateTime--2018年2月5日09:45:01 Author:Marydon 异常: Cause: java.sql.SQLException: ORA-12899: 列 " ...