Appium关于toast信息的识别

toast的识别条件

  • 设置caps中的automationName:uiautomator2
  • getPageSource是无法找到的toast信息
  • 必须使用xpath查找
    • //*[@class=‘android.widget.Toast’]
    • //@[contains(@text,“xxxxx”)]
from appium.webdriver.common.mobileby import MobileBy
from hamcrest import *

#配置程序入口信息
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By

class ContactsAndroidTests(unittest.TestCase):
    def setUp(self):
        caps = {}
        caps["platformName"] = "android"
        caps["deviceName"] = "xxxxx"
        caps["automationName"]="uiautomator2"
        caps["appPackage"]="io.appium.android.apis"
        caps["appActivity"]=".ApiDemos"
        #caps["resetKeyboard"]='true'
        #caps["udid"]="xxxxxxx"

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        self.driver.implicitly_wait(10)

    def test_toast(self):
        self.driver.find_element_by_accessibility_id("Views").click()
        self.driver.find_element_by_android_uiautomator(
            'new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "Popup Menu")'
        ).click()
        self.driver.find_element_by_accessibility_id("Make a Popup!").click()
        self.driver.find_element_by_android_uiautomator('new UiSelector().text("Search")').click()
        print(self.driver.find_element_by_xpath("//*[@class='android.widget.Toast']").text)
        ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值