Have a friend message response positioning element, yes, Captain also for this has been headache, I use the app is the original Android +WEBSERVICE+H5 type, positioning although no problem, but in the operation of the various do not pass ... It's really a headache. The "action" I'm talking about here means, for example, emptying the input box, entering a user name, and so on, but positioning is fine. Today first to show you a more standard app, with this there is no problem, in fact, the captain is lazy, because the operation of the calculator is really too simple ~.
My Baidu's "Calculator apk":
Then download the Xiaomi calculator:
The operation is: 12+1=
# Coding:utf-8
From AppiumImport Webdriver
From timeImport Sleepdesired_caps = {' PlatformName ':' Android ',
' DeviceName ':' 127.0.0.1:62001 ',
' Platformversion ':' 23 ',
' Apppackage ': ' com.miui.calculator ',
' appactivity ': ' com.miui.calculator.cal.CalculatorActivity '}
Driver = Webdriver. Remote ("Http://127.0.0.1:4723/wd/hub", Desired_caps) Sleep (2)
# Operation: 12+1=
# Resource-id
driver.find_element_by_id ("com.miui.calculator:id/btn_1"). Click ()
# text
Driver.find_element_by_name ("2"). Click ()
# Content-desc
DRIVER.FIND_ELEMENT_BY_ACCESSIBILITY_ID ("Plus"). Click ()
# class "Note: The index of 1 is 6,7 index is 0"
Driver.find_elements_by_class_name ("Android.widget.Button") [6].click ()
# Uiautomator
Driver.find_element_by_android_uiautomator (' new Uiselector (). Description ("equals") '). Click ()
I want to write some practical and strong, because the online search is full of calculators to do examples, the reason is here-the location and operation is not complex, write it easily and happy ...
Let the captain study the Android native and H5 hybrid app how to do ...
And thanks to the big God of wheat and apple. I'm too stupid to learn too slowly
Public search "automated test Practice" or scan the QR code below to add attention ~ ~ ~
Appium Positioning Method Example (4)