您好,欢迎来到汇意旅游网。
搜索
您的当前位置:首页Appium关于toast信息的识别

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)
        ```

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- hids.cn 版权所有 赣ICP备2024042780号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务