1.导入WebDriverWait、expected_conditions模块
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
2.在获取toast的页面,设置隐式等待,语句如下:
WebDriverWait(self.driver, 2).until(EC.presence_of_element_located((MobileBy.XPATH, ‘//*[contains(@text,"写够10个字呗~")]‘)))
备注:文字一定要正确,要不然找不到
3.实例:
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
def text_publish1(self):
"""
# 发布的文字少于10个字
:return:
"""
public_dict = YAML.yamlFile()[2][‘publish‘]
logging.info("准备发布纯文字")
self.driver.find_element_by_xpath(public_dict[‘textImg_btn‘]).click()
time.sleep(2)
self.driver.find_element_by_xpath(public_dict[‘text_content‘]).send_keys(public_dict[‘send_keys5‘])
time.sleep(2)
self.driver.find_element_by_xpath(public_dict[‘publish_btn‘]).click()
try:
WebDriverWait(self.driver, 2).until(EC.presence_of_element_located((MobileBy.XPATH, ‘//*[contains(@text,"写够10个字呗~")]‘)))
logging.info("请写够10个字")
except NoSuchElementException:
logging.info("没有弹出提示")
else:
self.driver.find_element_by_xpath(public_dict[‘text_content‘]).send_keys(public_dict[‘send_keys5‘+‘send_keys5‘])
self.driver.find_element_by_xpath(public_dict[‘publish_btn‘]).click()
logging.info("发布文字完成")
time.sleep(2)
self.driver.find_element_by_xpath(public_dict[‘last_tab‘]).click()
备注:找到toast之后,send_keys会清除之前输入的内容重新输入,不知道为啥~~~
Appium + python 获取toast