显示等待WebDriverWait+lambda

代码,关键代码标红

参考文章:https://www.cnblogs.com/yoyoketang/p/6517477.html

#coding:utf-8
‘‘‘
这里写了一个百度搜索页的pageobject
‘‘‘
from PageElement.readYaml import parseyaml
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Baidu_page():
    ‘‘‘
    百度搜索page类
    ‘‘‘

    getElement = parseyaml()

    search_box = getElement["baiduPage"]["search_box"]["value"]
    baidu_button = getElement["baiduPage"]["baidu_button"]["value"]
    search_result = getElement["baiduPage"]["search_result"]["value"]

    def __init__(self,driver):
        self.driver = driver

    def input_search(self,keyword,type_a="css"):
        ‘‘‘输入搜索关键词‘‘‘
        self.driver.find_element(type_a,self.search_box).send_keys(keyword)

    def click_baidubutton(self,type_a="css"):
        ‘‘‘点击百度一下按钮‘‘‘
        self.driver.find_element(type_a, self.baidu_button).click()

    def verification_result(self,type_a="css"):
        ‘‘‘用例结果验证‘‘‘
        WebDriverWait(self.driver,10).until(lambda x: x.find_element("css selector",self.search_result))

        results = self.driver.find_elements("css selector",self.search_result)
        nanjing_baike = results[0].text
        return nanjing_baike

原文地址:https://www.cnblogs.com/yrxns/p/11231629.html

时间: 2024-07-30 23:49:43

显示等待WebDriverWait+lambda的相关文章

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

我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中(appium通用)常用的等待分为显示等待WebDriverWait().隐式等待implicitly_wait().强制等待sleep()三种,下面我们就分别介绍一下这三种等待的区别 在前面的博文中简单介绍了<强制等待和隐士等待的区别和理解>,本文再详细的结合案例进行理解. sleep(): 强

显示等待WebDriverWait

显示等待:WebDriverWait 等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常 WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None) --driver:WebDriver 的驱动程序(Ie, Firefox, Chrome 或远程) --timeout:最长超时时间,默认以秒为单位 --poll_frequency:休眠时间的间隔(步长)时间,默认为

python selenium 中的显示等待WebDriverWait与条件判断expected_conditions

#coding=utf-8 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait base_url = "http://www.baidu.com"

selenium中的显示等待,隐示等待,强制等待

我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中(appium通用)常用的等待分为显示等待WebDriverWait().隐式等待implicitly_wait().强制等待sleep()三种,下面我们就分别介绍一下这三种等待的区别: 1.显式等待  WebDriverWait()      显式等待是你定义的一段代码,用于等待某个条件发生然后再

selenium等待方式之显示等待

有时候,页面元素并未及时加载出来导致后面的步骤无法执行 这里就需要在加载前添加等待时间,让目标元素有足够的时间加载出来 第一种方法:使用time.sleep() 这种方法过于强制,无论元素是否加载出来都要等指定的时间,导致脚本执行效率不高 第二种方法:隐式等待implicitly_wait() 这种方法比较全局性,意味着一旦启用,全局有效,所有步骤都需要等待所有页面元素加载完后才会继续执行后续脚本 第三种:显示等待WebDriverWait 通俗的说法,指定的某元素,等待加载出来后,再执行后续操

webdriver中的等待-WebDriverWait()

1.强制等待:sleep() from time import sleep sleep(3) #等待3秒 ****官方不推荐这样的方法,使用太多的sleep会影响脚本运行速度 2.隐式等待:implicitly_wait() driver.implicitly_wait(10) #隐式等待10秒 由webdriver提供的方法,一旦设置,这个隐式等待会在WebDriver对象实例的整个生命周期起作用,它不针对某一个元素,是全局元素等待,即在定位元素时,需要等待页面全部元素加载完成,才会执行下一个

9.0 toast定位+WebDriverWait显示等待

Toast  判断-----基本操作问题 首先基本操作,进入安卓市场的账号密码页面--- from appium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from appium.webdriver.common.touch_action import TouchA

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

# -*- coding: utf-8 -*- """ @author: Dell Created on Tue Dec 24 12:33:56 2019 """ import time from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait#等待一个元素加载完成 from selenium.webdriver.support i

python webdriver 显示等待-自动登录126邮箱,添加联系人

脚本内容:#encoding=utf-8#author-夏晓旭from selenium import webdriverimport timefrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.common.exceptions import TimeoutException, NoSuchElementExceptioni