甘肃住房城乡建设厅网站首页,巢湖seo推广,广东省网站备案注销,常德网站建设技术一、前置说明
toast消失的很快#xff0c;并且通过uiautomatorviewer也不能获取到它的定位信息#xff0c;如下图#xff1a;
二、操作步骤
toast的class name值为android.widget.Toast#xff0c;虽然toast消失的很快#xff0c;但是它终究是在Dom结构中出现过…一、前置说明
toast消失的很快并且通过uiautomatorviewer也不能获取到它的定位信息如下图
二、操作步骤
toast的class name值为android.widget.Toast虽然toast消失的很快但是它终究是在Dom结构中出现过所以我们可以使用xpath来定位toast元素 def get_toast(self, textNone, timeout3, interval0.5):# 如果同时出现多个toast可以使用这种方式if text:return WebDriverWait(self, timeout, interval).until(EC.presence_of_element_located((xpath, f//*[contains(text, {text})])))return WebDriverWait(self, timeout, interval).until(EC.presence_of_element_located((xpath, //*[classandroid.widget.Toast])))三、Demo验证
注意appium在v1.6.3以上才支持获取toast并且需要指定使用Uiautomator2库。
def test_get_toast():import logginglogging.basicConfig(levellogging.DEBUG)from driver.appium.driver import WebDriverappium_server_url http://localhost:4723capabilities {platformName: Android,automationName: uiautomator2, # 注意要指定uiautomator2deviceName: 127.0.0.1:62001,app: D:\\resources\\ApiDemos-debug.apk,}driver WebDriver(command_executorappium_server_url, capabilitiescapabilities)driver.smart_find_element(bytext, valueApp).click()driver.smart_find_element(bytext, valueNotification).click()driver.smart_find_element(bytext, valueNotifyWithText).click()driver.smart_find_element(bytext, valueSHOW SHORT NOTIFICATION).click()element driver.get_toast(Short notification)assert element.text Short notification日志输出 test session starts
collecting ... collected 1 itemtest_appium.py::test_get_toast PASSED 1 passed in 19.91s 欢迎技术交流