原文:https://www.cnblogs.com/lgh344902118/p/6015593.html

webdriver三种等待方法

1.使用WebDriverWait

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
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()

presence_of_element_located可以替换为

  • 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

By.ID中的ID可替换为'CLASS_NAME', 'CSS_SELECTOR', 'ID', 'LINK_TEXT', 'NAME', 'PARTIAL_LINK_TEXT', 'TAG_NAME', 'XPATH'

2、隐式等待,相当于设置全局的等待,在定位元素时,对所有元素设置超时时间。

隐式等待使得WebDriver在查找一个Element或者Element数组时,每隔一段特定的时间就会轮询一次DOM,如果Element或数组没有马上被发现的话。

默认设置是0。

一旦设置,这个隐式等待会在WebDriver对象实例的整个生命周期起作用。

from selenium import webdriver
driver = webdriver.Firefox()
driver.implicitly_wait(10) # seconds
driver.get(http://www.xxx.com)
myDynamicElement = driver.find_element_by_id("ElementID")

3、强制等待

import time

time.sleep(10)

【转】selenium webdriver三种等待方法的更多相关文章

  1. selenium webdriver三种等待方法

    webdriver三种等待方法 1.使用WebDriverWait from selenium import webdriverfrom selenium.webdriver.common.by im ...

  2. Python+Selenium自动化-设置等待三种等待方法

    Python+Selenium自动化-设置等待三种等待方法   如果遇到使用ajax加载的网页,页面元素可能不是同时加载出来的,这个时候,就需要我们通过设置一个等待条件,等待页面元素加载完成,避免出现 ...

  3. Selenium:三种等待方式

    UI自动化测试,大多都是通过定位页面元素来模拟实际的生产场景操作.但在编写自动化测试脚本中,经常出现元素定位不到的情况,究其原因,无非两种情况:1.有frame:2.没有设置等待. 因为代码运行速度和 ...

  4. Selenium中三种等待的使用方式---规避网络延迟、代码不稳定问题

    在UI自动化测试中,必然会遇到环境不稳定,网络慢的情况,这时如果你不做任何处理的话,代码会由于没有找到元素,而报错.这时我们就要用到wait(等待),而在Selenium中,我们可以用到一共三种等待, ...

  5. Python selenium 三种等待方法

    1. 强制等待 sleep(xx) 是最简单粗暴的一种办法,不管你浏览器是否加载完了,程序都得等待3秒,3秒一到,继续执行下面的代码,作为调试很有用,不建议总用这种等待方式,严重影响程序执行速度. 代 ...

  6. python之selenium三种等待方法

    前提: 我们在做Web自动化时,有的时候要等待元素加载出来,才能操作,不然会报错 1.强制等待 2.隐式等待 3.显示等待 内容: 一,强制等待 这个比较简单,就是利用time模块的sleep的方法来 ...

  7. selenium的三种等待

    1. 强制等待 最简单粗暴,sleep(xx),不管你浏览器是否加载完了,程序都得等待xx秒,时间一到,再继续执行下面的代码,作为调试很有用,有时候也可以在代码里这样等待,不过不建议总用这种等待方式, ...

  8. web自动化测试-selenium的三种等待

    一.等待的作用 1.在系统的功能运行过程中,所有的内容是需要一定的时间来实现展示, 2.时间耗费长短与网络速度.系统框架设定.接口的执行复杂度有关, 3.因此需要设置缓冲时间,若未设置缓冲时间,容易导 ...

  9. Selenium4+Python3系列(六) - Selenium的三种等待,强制等待、隐式等待、显式等待

    为什么要设置元素等待 直白点说,怕报错,哈哈哈! 肯定有人会说,这也有点太直白了吧. 用一句通俗易懂的话就是:等待元素已被加载完全之后,再去定位该元素,就不会出现定位失败的报错了. 如何避免元素未加载 ...

随机推荐

  1. java mail 读取邮件列表,

    // 准备连接服务器的会话信息 Properties props = new Properties(); props.setProperty("mail.store.protocol&quo ...

  2. connect: Address is invalid on local machine or port is not valid on remote

    idea 运行正常打成jar包运行提示“connect: Address is invalid on local machine or port is not valid on remote” , 解 ...

  3. 找不到类SimpleJdbcTemplate ParameterizedRowMapper cannot be resolved

    找不到类SimpleJdbcTemplate 背景 想编译个web应用,原来spring-jdbc.jar用的是Spring 3.1,今天改成用Spring 4.3,报了这个错误. 现象 编译不通过, ...

  4. Oracle安装配置

    很久没有使用Oracle了,一直做产品使用Mysql,前段时间使用Oracle的一些新经验,占位. 需要整理下....

  5. hibernate配置文件 连接数据库

    http://jingyan.baidu.com/album/0320e2c1d4dd0b1b87507b38.html?picindex=12

  6. centos6 搭建nginx实现负载均衡

    一.安装nginx 1)准备2台服务器,环境一样,同时执行 rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.r ...

  7. samba服务和nginx服务

    一  samba服务 1 samba的功能:samba是一个网络服务器,是连接linux和windows之间共享文件的. 2 samba服务的启动,停止和重启: (1) 要启动Samba服务,只需用户 ...

  8. 2018.11.05 NOIP模拟 相交(dfs序+bit)

    传送门 又TMTMTM考原题真是服. 考虑到两条路径相交一定满足某一条的lcalcalca在另外一条路径上面. 于是分开统计有多少个lcalcalca在当前路径上面以及有多少个路径经过了当前的lcal ...

  9. 在vue或者react中使用express框架

    在react 或者 vue项目中使用express框架 1.创建vue或者 react 项目 2.在项目中创建server文件夹,创建server.js //require()方法引入express模 ...

  10. jitter

    release jitter of tasks there is a distinction between the real activation request and the actual ac ...