appium获取Toast内容的方法

金鞍玉勒寻芳客,未信我庐别有春。这篇文章主要讲述appium获取Toast内容的方法相关的知识,希望能为你提供帮助。
做自动化测试的时候,可能需要根据弹出的Toast提示来做下一步判断。这里记录一下获取Toast内容的方法,同时巩固一下显示等待的方法之一WebDriverWait。

from selenium.webdriver.support import expected_conditions as ecdef find_toast(self, driver, message, timeout=10, poll=0.01): try: message = ‘//*[@text=\‘{}\‘]‘.format(message) #Toast内容 element = WebDriverWait(driver, timeout,poll).until(ec.presence_of_element_located((By.XPATH, message))) return True except Exception as e: print(("Get Toast Error : ", e)) return False

【appium获取Toast内容的方法】presence_of_element_located可以替换为
  • title_is
  • title_contains
  • presence_of_element_located
  • visibility_of_element_located   # 和 presence_of_element_located 的作用几乎一样
  • visibility_of
  • presence_of_all_elements_located
  • text_to_be_present_in_element
  • text_to_be_present_in_element_value
  • frame_to_be_available_and_switch_to_it
  • invisibility_of_element_located
  • element_to_be_clickable - it is Displayed and Enabled.
  • staleness_of
  • element_to_be_selected
  • element_located_to_be_selected
  • element_selection_state_to_be
  • element_located_selection_state_to_be
  • alert_is_present
By.XPATH中的XPATH可替换为‘CLASS_NAME‘, ‘CSS_SELECTOR‘, ‘ID‘, ‘LINK_TEXT‘, ‘NAME‘, ‘PARTIAL_LINK_TEXT‘, ‘TAG_NAME‘
 

    推荐阅读