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