Appium Positioning Method Example (4)

Source: Internet
Author: User
Tags appium

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.