日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

element ui select设置不显示不存在的项_appium—等待时间设置方法

發(fā)布時間:2025/3/11 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 element ui select设置不显示不存在的项_appium—等待时间设置方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

引言:

在做UI自動化的過程中,我們有時候為了等待元素的出現(xiàn),需要加一些等待時間來幫助,但是有時候時間加的過多或者過少,這個沒有辦法判斷,今天就介紹幾種等待時間,我們看看那種適合我們

一、強(qiáng)制等待

看到名稱就應(yīng)該知道,強(qiáng)制等待,就是設(shè)置多少秒,就必須等待多少秒,才能繼續(xù)往下面操作

time.sleep()

def sleep(seconds): # real signature unknown; restored from __doc__

"""

sleep(seconds)

延遲指定的秒數(shù)

"""

pass

使用方法

# 直接在需要等待的地方添加 time.sleep(10)

二、隱式等待

隱式等待: implicitly_wait?() 默認(rèn)參數(shù)的單位為妙,設(shè)置一個等待時間,它并不影響腳本的執(zhí)行速度。當(dāng)腳本執(zhí)行到某個元素定位是,如果元素可以定位,則繼續(xù)執(zhí)行,如果元素定位不到,則它將以輪詢的方式不斷地判斷元素是否被定位到。假設(shè)在第六秒定位到了元素則繼續(xù)執(zhí)行,若直到超出設(shè)置的時長10秒還沒有定位到元素,則拋出異常。

def implicitly_wait(self, time_to_wait):

"""

Sets a sticky timeout to implicitly wait for an element to be found,

or a command to complete. This method only needs to be called one

time per session. To set the timeout for calls to

execute_async_script, see set_script_timeout.

:Args:

- time_to_wait: Amount of time to wait (in seconds)

:Usage:

driver.implicitly_wait(30)

"""

if self.w3c:

self.execute(Command.SET_TIMEOUTS, {

'implicit': int(float(time_to_wait) * 1000)})

else:

self.execute(Command.IMPLICIT_WAIT, {

'ms': float(time_to_wait) * 1000})

使用方法:

# 在需要等待的地方直接添加 driver.implicitly_wait(10)

三、Activity等待

Activity等待: app特有一種等待,通過Activity的出現(xiàn)來幫助我們進(jìn)行判斷是否到達(dá)這個頁面然后進(jìn)行一系列的操作 ,通過wait_activity 進(jìn)行判斷

def wait_activity(self, activity, timeout, interval=1):

"""等待一個activity,直到在規(guī)定時間內(nèi)activity出現(xiàn)

This is an Android-only method.

:Args:

- activity - target activity

- timeout - max wait time, in seconds

- interval - sleep interval between retries, in seconds

"""

try:

WebDriverWait(self, timeout, interval).until(

lambda d: d.current_activity == activity)

return True

except TimeoutException:

return False

使用方法:

直接在需要等待元素出現(xiàn)的地方添加

# 添加activity,后面加上等待的時間,超過時間就報錯 driver.wait_activity('com.ali.user.mobile.login.ui.UserLoginActivity',30)

四、顯示等待

顯示等待本來準(zhǔn)備等到寫selenium教程的時候在介紹,感覺后面會用,這里就直接給大家進(jìn)行介紹了。 如果對軟件測試、接口測試、自動化測試、面試經(jīng)驗交流。感興趣可以加測試交流群,還會有同行一起技術(shù)交流。

先看源碼:

def __init__(self, driver, timeout, poll_frequency=POLL_FREQUENCY, ignored_exceptions=None):

"""

driver: 返回一個webdriver實例化

timeout:設(shè)置一個超時時長(S)

poll_frequency:循環(huán)讀取元素的時間,默認(rèn)是0.5(s)

使用方法 :

from selenium.webdriver.support.ui import WebDriverWait n

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

is_disappeared = WebDriverWait(driver, 30, 1, (ElementNotVisibleException)). n

until_not(lambda x: x.find_element_by_id("someId").is_displayed())

"""

self._driver = driver

self._timeout = timeout

self._poll = poll_frequency

# avoid the divide by zero

if self._poll == 0:

self._poll = POLL_FREQUENCY

exceptions = list(IGNORED_EXCEPTIONS)

if ignored_exceptions is not None:

try:

exceptions.extend(iter(ignored_exceptions))

except TypeError: # ignored_exceptions is not iterable

exceptions.append(ignored_exceptions)

self._ignored_exceptions = tuple(exceptions)

從源碼中分許出來三個參數(shù)的作用

driver:返回一個webdriver實例化

timeout:設(shè)置一個超時時長

poll_frequentcy:循環(huán)讀取元素時間

使用方法:

# 導(dǎo)入方法 from selenium.webdriver.support.ui import WebDriverWait element = WebDriverWait(driver, 10).until(lambda x: x.find_element_by_id("someId"))

總結(jié)

以上是生活随笔為你收集整理的element ui select设置不显示不存在的项_appium—等待时间设置方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。