python + Appium automation: toast positioning

Toast Profile

Toast is a simple message box.

When the view displayed to the user, as displayed in floating applications. And Dialog is not the same, it never gets focus, can not be clicked.

Users will probably typed something else in the middle. Toast class ideology is as unobtrusive as possible, and also displays information to the user, want them to see.

Toast and the limited time shown, Toast according to disappear automatically after the display time set by the user.

For example: toast image below is the information that appears when you exit the app Taobao

 

If UI Automation Viewer tool is unable to locate, and then how to locate it?

This is mainly based UiAutomator2, requiring disposed Capablity following parameters:

'automationName': 'uiautomator2'

Installation appium-uiautomator2-driver:

cnpm install appium-uiautomator2-driver

After a successful installation can be in C: \ Users \ XX path \ node_modules see the corresponding file:

@ @ appium 1.23.0 _appium-uiautomator2-driver-driver-uiautomator2

_appium uiautomator2-server-2.6.0 @ @ appium-server-uiautomator2

 

 

Specific code as follows:

from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
import time
from selenium.webdriver.support.ui import WebDriverWait


desired_caps = {
"platformName": "Android",
"platformVersion": "5.1",
"deviceName": "U4KF9HSK99999999",
"appPackage": "com.taobao.taobao",
"appActivity": "com.taobao.tao.welcome.Welcome",
"unicodeKeyboard":True,
"resetKeyboard":True,
"noReset": True,
"automationName": "Uiautomator2"
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
time.sleep(1)
driver.back () 
# xpath positioned with
toast_message = "press the return key to exit the phone Taobao"
Message = '// * [@ text = \' {} \ ']'. the format (toast_message)
# shows the wait detection element
toast_element WebDriverWait = (Driver, 5) .until (the lambda the X-: x.find_element_by_xpath (the Message))
Print (toast_element.text)
# results were compared
assert toast_element.text == "press the return key to exit the phone Taobao"
 

Guess you like

Origin www.cnblogs.com/bugbreak/p/12048032.html