一、Appium-python-UI自動化之元素定位-獲取APP中的toast,判斷該元素是否存在

獲取如圖的toast提示

 

 

 

 

 直接上代碼:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
 
def is_toast_exist(driver,text=None,timeout=30,poll_frequency=0.5):
 
   '''is toast exist, return True or False
   :Agrs:
    - driver - 傳driver
    - text   - 頁面上看到的文本內容
    - timeout - 最大超時時間,默認30s
    - poll_frequency  - 間隔查詢時間,默認0.5s查詢一次
   :Usage:
    is_toast_exist(driver, "看到的內容")
   '''
 
   try:
       toast_loc = ("xpath", ".//*[contains(@text,'%s')]"%text)
       WebDriverWait(driver, timeout, poll_frequency).until(EC.presence_of_element_located(toast_loc))
       return True
   except:
       return False
發佈了49 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章