等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常

WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None)

-driver:WebDriver 的驱动程序(Ie, Firefox, Chrome 或远程)

-timeout:最长超时时间,默认以秒为单位

-poll_frequency:休眠时间的间隔(步长)时间,默认为 0.5 秒

-ignored_exceptions:超时后的异常信息,默认情况下抛 NoSuchElementException 异常

例子1:

element = WebDriverWait(driver, 10).until(lambda x : x.find_element_by_id("id"))

element.send_keys("selenium")

例子2:

element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id(“Id”))

is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)).until_not(lambda x: x.find_element_by_id(“someId”).is_displayed())

WebDriverWai()一般由 unit()或 until_not()方法配合使用:

-until(method, message=’’)      调用该方法提供的驱动程序作为一个参数,直到返回值不为 False。

-until_not(method, message=’’)      调用该方法提供的驱动程序作为一个参数,直到返回值为 False。

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
driver=webdriver.Firefox()
driver.get()
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id("someId"))

#通过检查某个元素是否被加载来检查是否登录成功,我认为当个黑盒子用就可以了。其中10的解释:10秒内每隔0.5毫秒扫描1次页面变化,直到指定的元素

WebDriverWait显示等待的更多相关文章

  1. 9.0 toast定位+WebDriverWait显示等待

    Toast  判断-----基本操作问题 首先基本操作,进入安卓市场的账号密码页面--- from appium import webdriver from selenium.webdriver.su ...

  2. selenium中的三种等待方式(显示等待WebDriverWait()、隐式等待implicitly()、强制等待sleep())---基于python

    我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中 ...

  3. Selenium 定位元素原理,基本API,显示等待,隐式等待,重试机制等等

    Selenium  如何定位动态元素: 测试的时候会遇到元素每次变动的情况,例如: <div id="btn-attention_2030295">...</di ...

  4. python selenium2 中的显示等待WebDriverWait与条件判断expected_conditions举例

    #coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium. ...

  5. 显示等待WebDriverWait

    显示等待:WebDriverWait 等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常 WebDriverWait(driver, timeout, poll ...

  6. 【转】python selenium2 中的显示等待WebDriverWait与条件判断expected_conditions举例

    #coding=utf-8 from selenium import webdriver from selenium.webdriver.common.by import By from seleni ...

  7. selenium相关导入By、Keys、WebDriverWait、ActionChains,显示等待与隐式等待

    # -*- coding: utf-8 -*- """ @author: Dell Created on Tue Dec 24 12:33:56 2019 "& ...

  8. Selenium 显示等待和隐式等待

    1. 设置显示等待 Java代码: 1 2 3 4 5 public static WebElement WaitForElement(WebDriver driver, String locator ...

  9. Selenium+Java显示等待和隐式等待

    描述:用来操作界面上的等待时间,显示等待是等待某一条件满足,条件满足后进行后面的操作:隐式等待是给出一个等待时间,在时间到达之前若满足条件,则立即执行后续操作. public class TestSe ...

随机推荐

  1. hdu 1711kmp裸题

    #include<stdio.h> #define N 1000050 int text[N],t[N],next[N],n,m; void getnext() { int j=0,k=- ...

  2. K/3Cloud二次开发基于WebDev附加进程调试

    大部分人在进行K/3cloud二次开发插件的调试时,选择的是附加IIS进程w3wp调试,本文给大家介绍一下基于WebDev附加进程调试,不用重启iis. 步骤如下: 1)拷贝K/3cloud产品安装目 ...

  3. 旅行(bzoj 3531)

    Description S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天面条神教.隐形独角兽教.绝地教都是常见的信仰. ...

  4. 【cmd】cmd常用命令

    dir 是英文单词directory(目录)的缩写,主要用来显示一个目录下的文件和子目录 md  是英文make directory(创建目录)的缩写 cd  是英文change directory( ...

  5. express 写接口

    实例下载:百度云盘免密码 (): 指注释 一.准备工作 1.安装express npm install express -g npm install express-generator -g 2.初始 ...

  6. POJ 2513 【字典树】【欧拉回路】

    题意: 有很多棒子,两端有颜色,告诉你两端的颜色,让你把这些棒子拼接起来要求相邻的接点的两个颜色是一样的. 问能否拼接成功. 思路: 将颜色看作节点,将棒子看作边,寻找欧拉通路. 保证图的连通性的时候 ...

  7. mongodb按照日期分组统计

    目录 1.使用时间格式化方法 2.进行时间补偿(默认当前时区是东八区,即8x3600x1000=28800000) mongodb的默认时间是格林尼治时间,如果是要按照日期进行分组需要注意!!!. 解 ...

  8. maven 将项目打成jar包

    添加此plugin到项目的pom.xml <project xmlns=</modelVersion>     <groupId>fuck</groupId> ...

  9. Exception: Could not bind to 0.0.0.0:8080 after trying for 30 seconds

    swift@vincent-virtual-machine /etc/swift $ sudo swift-init main restart Signal proxy-server pid: sig ...

  10. python执行系统命令的几种方法

    (1) os.system 这个方法是直接调用标准C的system() 函数,仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息. import os os.system('cat /pro ...