Appium+python Positioning method

Source: Internet
Author: User

Introduce several simple positioning methods of Appium

1. ID Location
Format: driver.find_element_by_id ("Here is Resource-id")
driver.find_element_by_id ("Com.taobao.taobao:id/home_searchedit")
2. Name positioning
Location, you can locate it by name
Format: Driver.find_element_by_name ("Here is Text")
Driver.find_element_by_name ("No need to match the newest")
Note: appium1.5 the following old version can be located by name, the new version from 1.5 does not support name positioning * *
(If the Text property is empty, it cannot be located by the Name property)
3. Class positioning
Format: Driver.find_element_by_class_name ("Class attribute")
Driver.find_element_by_class_name ("Android.widget.EditText")
(Note: Generally a page of the class attribute is not unique, the element is not unique, the location will be error)
4. accessibility_id positioning is the Content-desc property viewed through the UI Automator tool
(Of course, the Content-desc property is empty, it cannot be positioned by this attribute, here is just an example)
When you see the Content-desc attribute has a value, you can use accessibility_id to locate the

Format: driver.find_element_by_accessibility_id ("Content-desc value")

driver.find_element_by_accessibility_id ("xxx")

(Note: Generally a page of the class attribute is not unique, the element is not unique, the location will be error)
In addition to the above, which are positioned through attributes, the complex point can also be located by XPath and Androiduiautomator.

5, list positioning, that is, listing positioning. driver.find_elements_by_id ("Com.baidu.yuedu:id/tab_search") [0].click ().
Description: Some list page pages do not have an id attribute and have a class attribute, but the class attribute is not unique. Or there is an id attribute, but the ID property of the list is the same. This time you can use the list to locate, take the same ID or the same class, locate a set of elements, and then the subscript out of the element, you can locate the element you want to remove.
Singular positioning: find_element for positioning singular
Complex position: find_elements for locating complex numbers
Example:
Searchs = driver.find_elements_by_id ("Com.baidu.yuedu:id/tab_search")
Print (searchs) # Printing list
Print (Type (searchs))
This navigates to the list type
After locating a group, if you want to click on the element, first remove the element object from the list by subscript index, then click on it. The subscript index is starting from 0.
# list Locator
driver.find_elements_by_id ("Com.baidu.yuedu:id/tab_search") [0].click ()

6. XPath positioning
Appium after version 1.5, the name location method is not available, you can use XPath instead
XPath syntax in appium://*[@text = ' page text ')
Example:
Driver.find_element_by_xpath ("//*[@text = ' novel ']"). Click ()
What if the text value of an interface is not unique?
XPath syntax inside * is to match any value, in Selenium * is to match any tag, Appium * is to match any class name, if a few text class attribute is different, you can use the following combination:

Appium+python Positioning method

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.