脚本宝典收集整理的这篇文章主要介绍了25、显示等待,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
# 参数
# driver:驱动对象
# timeout:超时的市场,单位:秒
# poll_frequency:检测间隔时间,单位为0.5秒
# 返回值
# WebDriverWait对象
WebDriverWait(driver, timeout, poll_frequency=0.5)
# 参数
# method:lambda查找元素表达式
# 返回值
# 定位到的元素,如果没有定位到会抛出TimeoutException异常
wait.until(method)
From appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
import time
desired_caps = dict()
desired_caps['platformName'] = 'AndROId'
desired_caps['platformVersion'] = '7'
desired_caps['deviceName'] = '192.168.101.55:5555'
# 手机参数
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
PRint('---开始准备点击了')
# 拆分的写法
# wait = WebDriverWait(driver, 5, 1)
# back_button = wait.until(lambda x: x.find_element_by_xpath('//*[@content-desc="收起"]'))
# back_button.click()
# 简便的写法
WebDriverWait(driver, 5, 1).until(lambda x: x.find_element_by_xpath('//*[@content-desc="收起"]')).click()
# 使用显式等待,在20秒的时间内,每3秒钟找一次,id为xx的元素
WebDriverWait(driver, 20, 3).until(lambda x: x.find_element_by_id('xx'))
print('---点完了')
以上是脚本宝典为你收集整理的25、显示等待全部内容,希望文章能够帮你解决25、显示等待所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。