Appium for Android Find element method summary

Source: Internet
Author: User
Tags appium

using appium test app Automation to find elements is cumbersome, no selenium find Web page elements convenient,

And the limitations are relatively high, use is not too flexible.

So here are some of the methods we usually use to find elements (for example, a hammer phone).

There are two tools you can use to find elements: Android SDK Bring your own Uiautomator Viewer ; Appium Latest Version 1.0.2 .

Recommended Use Uiautomator Viewer , personal feeling is convenient to use, including the value of copying elements is also more convenient .

First link Hammer Phone:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/98/EF/wKioL1lCFNHwAg-jAAnXaulvUfI675.png-wh_500x0-wm_ 3-wmp_4-s_1844556913.png "title=" link hammer. png "alt=" wkiol1lcfnhwag-jaanxaulvufi675.png-wh_50 "/>

There are many ways to do this:

through Xpyth positioning : Findelementbyxpath ("//android.widget.textview[10]") XPath Subscript from 1 start by using the full ClassName

through text name : find_element_by_name ( name corresponds to uiautomator after scanning text content)

through ID : find_element_by_id ( ID corresponding Resource-id)

through ClassName Positioning: find_element_by_class_name (class_name corresponds to Class)

through Accessibility ID : find_element_by_accessibility_id (accessibility_id corresponds to content-desc)

Navigate to a text box and enter the contents:

driver.find_element_by_id ("xxxxx"). Send_keys ("123456")

Slide Screen:

Get screen size width=self.driver.get_window_size () [' Width ']height=self.driver.get_window_size () [' Height ']

Slide Screen driver.swipe (WIDTH*9/10, HEIGHT*1/2, WIDTH*1/10, HEIGHT*1/2, +)

Open the headlines on your phone and just describe the three common ones:

    • Find_element_by_name ( name corresponding Uiautomator after scanning text 's content)

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/98/EF/wKiom1lCF5WilQI2AAL6riQ-qKQ644.png-wh_500x0-wm_ 3-wmp_4-s_4246146957.png "title=" by Name.png "alt=" Wkiom1lcf5wilqi2aal6riq-qkq644.png-wh_50 "/>

enter this in the script name You can navigate to this element and do the appropriate actions, such as Click () wait

    • find_element_by_id ( ID corresponding Resource-id , use this to find more accurate )

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/98/EF/wKiom1lCF7DiqKoDAAJbVqR-2EI868.png-wh_500x0-wm_ 3-wmp_4-s_1191035454.png "title=" by Id.png "alt=" Wkiom1lcf7diqkodaajbvqr-2ei868.png-wh_50 "/>

with Resource-id Search is the most accurate!

    • find_element_by_class_name (class_name corresponds to class, this is generally found in a bunch of data, because there are many places to use the same class name)

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/98/EF/wKiom1lCF8jg5bu8AAKsnIHD3cA145.png-wh_500x0-wm_ 3-wmp_4-s_3262231643.png "title=" Classname.png "alt=" Wkiom1lcf8jg5bu8aaksnihd3ca145.png-wh_50 "/>

This is the name of Android.widget.TextView of the ClassName , all the other lines are this . name

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/98/EF/wKioL1lCF-zDeb0yAAIwjNLvqtY632.png-wh_500x0-wm_ 3-wmp_4-s_306117541.png "title=" Class Name.png "alt=" Wkiol1lcf-zdeb0yaaiwjnlvqty632.png-wh_50 "/>

Look, the rest is the same. class name , so using this lookup will find out a list of data, if you want to take a row of data separately, you need to use for follow the bad or the script to fetch [X]

in doing app Automation takes a lot of effort to get the data in advance and organize it, because a lot of data is not

The corresponding.

there are problems to add QQ Group: 610845268


This article is from the "It Bug" blog, so be sure to keep this source http://laomomo.blog.51cto.com/6595318/1937024

Appium for Android Find element method summary

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.