Appium Python V: element positioning

Source: Internet
Author: User

Summarize individual element positioning:

DRIVER.FIND_ELEMENT_BY_ACCESSIBILITY_ID (ID)
Driver.find_element_by_android_uiautomator (uia_string)
Driver.find_element_by_class_name (name)
Driver.find_element_by_css_selector (Css_selector)
DRIVER.FIND_ELEMENT_BY_ID (ID_)
Driver.find_element_by_ios_predicate (predicate_string)
Driver.find_element_by_ios_uiautomation (uia_string)
Driver.find_element_by_link_text (Link_text)
Driver.find_element_by_name (name)
Driver.find_element_by_partial_link_text (Link_text)
Driver.find_element_by_tag_name (name)
Driver.find_element_by_xpath (XPath)

Multiple element positioning:

DRIVER.FIND_ELEMENTS_BY_ACCESSIBILITY_ID (ID)
Driver.find_elements_by_android_uiautomator (uia_string)
Driver.find_elements_by_class_name (name)
Driver.find_elements_by_css_selector (Css_selector)
DRIVER.FIND_ELEMENTS_BY_ID (ID_)
Driver.find_elements_by_ios_predicate (predicate_string)
Driver.find_elements_by_ios_uiautomation (uia_string)
Driver.find_elements_by_link_text (text)
Driver.find_elements_by_name (name)
Driver.find_elements_by_partial_link_text (Link_text)
Driver.find_elements_by_tag_name (name)
Driver.find_elements_by_xpath (XPath)

Other:

There are also two private methods:

Driver.find_element (by, value)

Driver.find_elements (by, value)

The difference between positioning a single element and locating multiple elements is that a single element is positioned back as a single element, and multiple element positioning returns a list of elements that contain more than one element.

The private method of the other parts here, because it belongs to private, is not generally used directly.

Detailed introduction 1. find_element_by_id

Usage: Find elements by Element ID

Example: driver.find_element_by_id (' com.android.calculator2:id/digit8 ')

Here the element ID and the resource ID of the element in Uiautomatorview are consistent.

It is important to note that Android 4.3 and above will have the resource ID. I tried the Android 4.2.2 system and the result resource ID here has been empty.

2. find_element_by_accessibility_id (ID)

Example: driver.find_element_by_accessibility_id ("delete")

The accessibility ID here is consistent with the content-desc of the element in Uiautomatorview.

3. Find_element_by_name (name)

Usage: Find elements by element name

Example: Driver.find_element_by_name ("Create a new Contact")

The name here is consistent with the text of the element in Uiautomatorview.

It is important to note that this positioning method is not recommended because Appium v1.0 has deprecated the way to locate using name.

4. Find_element_by_class_name (name)

Usage: Find elements through the element class name

Example: Driver.find_element_by_class_name ("Android.widget.Button")

The class name here is consistent with the class of the element in Uiautomatorview.

It is important to note that because class name is not unique, there may be multiple elements on a page that have the same class name.

5. Find_element_by_xpath (XPath)

Usage: Find elements by Element XPath

Example: Driver.find_element_by_xpath ("//android.widget.button[@text = ' 8 ']")

The advantage of locating with XPath is that, to be more absolute, any element can be positioned by XPath.

The original Uiautomatorview is a tutorial that does not see the XPath attribute, and the web has an extended uiautomatorview that allows it to display XPath directly.

You can download the extended version of Lazyuiautomatorviewer directly: Automated test intermediate--lazyuiautomatorviewer plugin development and usage instructions

The extended version of Lazyuiautomatorviewer can be seen with the XPath attribute at the bottom. Of course, if you are familiar with XPath syntax, you can also write the XPath of the element directly through the hierarchical relationship.

6. Find_element_by_android_uiautomator (uia_string)

To use: Position by positioning in the Uiautomator

Example: Driver.find_element_by_android_uiautomator (' New Uiselector (). ResourceId ("Com.android.calculator2:id/digit8") ‘)

This can be done by Uiselector () in a variety of ways, the above is just an example of the use of ResourceID only.

Other positioning methods

Find_element_by_css_selector (Css_selector)

Find_element_by_tag_name (name)

Find_element_by_link_text (Link_text)

Find_element_by_partial_link_text (Link_text)

Appium Python V: element positioning

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.