Write in front:
This article describes the identification of the elements of the tools and elements of the positioning method, the tools to identify elements are mainly uiautomator and monitor, as well as Appium Inspector (small series under the windows in the 1.7.0 version can be used, 1.4.16 version is not available), This series of tutorials with the appium1.4.16 this article, it is not introduced Appium Inspector.
First, the common identification elements of the tool introduction
- Start Uiautomatorviewer.bat/monitor.bat. Open the Sdk/tools directory to find Uiautomatorviewer.bat/monitor.bat.
- Double-click to start after startup
Second, monitor connect mobile phone
- Win+r shortcut key input cmd Open, enter ADB devices, confirm the current device access.
- Open the main screen of the Magic Diffuse camera, click the Mobile robot icon in the Monitor interface, this button will refresh the latest interface every time
Third, positioning elements
- Move the mouse to the area of the element that you want to locate, and click to make the Red solid line box live. Click the button to enter the comics
Node detail can see the attributes of the element
Resource-id:com.manboker.headportrait:id/entry_album_set
Class:android.widget.ImageView
Used when the index interface has multiple identical properties
Four, click on my button
Navigate and click through Resource-id. The final code is as follows:
#Coding:utf-8Import Time fromAppiumImportWebdriverdesired_caps={}desired_caps['devicename'] ='192.168.199.101:5555'desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='5.0'desired_caps['Apppackage'] ='com.manboker.headportrait'desired_caps['appactivity'] ='com.manboker.headportrait.activities.FirstActivity'Driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps) time.sleep (8)#Sleep 8 secondsDRIVER.FIND_ELEMENT_BY_ID ('Com.manboker.headportrait:id/entry_album_set'). Click ()#点击进入我的页面driver.quit ()
Five, Appium tool simple use introduction
- Double-click Appium.exe to open, into the setting interface. The following 1 is the path of the APK being tested, 2 viewing the app's package name and launch activity,3 is the device name of the app under test.
- Open Appium
Confirm the phone successful computer, click the triangle icon to the right of the search button to start the Appium service, when the interface appears as follows, the service has been started.
- Remote control (appium--general setting interface)
Appium The default service address is the 127.0.0.1 port number 4723, which is normally debugged on the local machine without modification.
if remote to an automated test computer to run this IP will come in handy, by modifying the following code can be
Driver = Webdriver. Remote ('http://localhost:4723/wd/hub', Desired_caps)
Change to:
Driver = Webdriver. Remote ('http://192.168.0.105:4723/wd/hub', Desired_caps)
As follows: Ipconfig view computer IP
- Remote connection
Browser input: Http://192.168.0.105:4723/wd/hub, see the following interface to prove the success of the remote link
- The code in the script is modified as follows
#Coding:utf-8Import Time fromAppiumImportWebdriverdesired_caps={}desired_caps['devicename'] ='192.168.199.101:5555'desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='5.0'desired_caps['Apppackage'] ='com.manboker.headportrait'desired_caps['appactivity'] ='com.manboker.headportrait.activities.FirstActivity'Driver= Webdriver. Remote ('Http://192.168.0.105:4723/wd/hub', Desired_caps) time.sleep (8)#Sleep 8 secondsDRIVER.FIND_ELEMENT_BY_ID ('Com.manboker.headportrait:id/entry_album_set'). Click () time.sleep (5) Driver.quit ()
Vi. element Positioning (common methods)
- Location by ID
Take Resource-id value: driver.find_element_by_id (' Com.manboker.headportrait:id/entry_album_set ')
- Positioning via Class_name
Take class content: Driver.find_element_by_class_name ("Android.widget.ImageView")
- Navigate through text
Use the contents of text: Driver.find_elements_by_android_uiautomator ("New Uiselector (). Text (\" login \ ")")
- Positioning by name: Driver.find_element_by_name ()
- Positioning via XPath: Driver.find_element_by_xpath ("//android.widget.textview[@resource-id=\" Com.manboker.headportrait:id/ Nologin_retry\ "]")
- Positioning via Css_selector: Driver.find_element_by_css_selector ()
As above, the Pycharm input driver.find_element_by will automatically match.
OK, this article describes this, the next article describes the Appium Python API.
Appium+python Mobile Automation Test (iv)--monitor/uiautomatorviewer tool and element location method