toast提示信息获取

toast获取的前提条件
1、desired_caps["automationName"]="UiAutomator2"
2、要求安装jdk1.8 64位及以上。配置其环境变量JAVA_HOME 和path
3、Android 系统5.0以上;(夜神模拟器默认的安卓版本是4.4.2,可以在夜神多开器中创建并启动一个5.1.1的版本)
4、appium server 版本1.6.3以上
5、xpath 表达查找toast
6、只能等待toast存在,而不能等待可见

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from appium.webdriver.common.touch_action import TouchAction

#启动参数
desired_caps={}
desired_caps['automationName']='UiAutomator2'
desired_caps["platformName"] = "Android"
desired_caps["platformVersion"] = "5.1"
desired_caps["deviceName"] = "Android Emulator"
desired_caps["noReset"] = True

#保证终端设备上,已安装了对应的app。
desired_caps["appPackage"] = "com.lemon.lemonban"
desired_caps["appActivity"] = "com.lemon.lemonban.activity.WelcomeActivity"

#连接appium server,然后告诉它server,我要干什么。
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)

#首页-点击我的柠檬
WebDriverWait(driver,20).until(EC.visibility_of_element_located((MobileBy.ID,'com.lemon.lemonban:id/navigation_my')))
driver.find_element_by_id('com.lemon.lemonban:id/navigation_my').click()

#点击我的头像-----等待元素可见
WebDriverWait(driver,20).until(EC.visibility_of_element_located((MobileBy.ID,'com.lemon.lemonban:id/fragment_my_lemon_avatar_layout')))
driver.find_element_by_id('com.lemon.lemonban:id/fragment_my_lemon_avatar_layout').click()

#点击登录按钮
WebDriverWait(driver,20).until(EC.visibility_of_element_located((MobileBy.ID,'com.lemon.lemonban:id/btn_login')))
driver.find_element_by_id('com.lemon.lemonban:id/btn_login').click()

#获取toast信息
#toast:使用xpath表达式
#不能用等待元素可见。只能用等待元素存在
toast_loc = '//*[contains(@text,"手机号码或密码")]'
try:
WebDriverWait(driver,5,0.01).until(EC.presence_of_all_elements_located((MobileBy.XPATH,toast_loc)))
print(driver.find_element_by_xpath(toast_loc).text)
except:
print('没有获取到toast信息')

#注意事项:注意等待的时间,toast等待时间要快一点
 


转载于:https://www.cnblogs.com/sophia-985935365/p/10756113.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值