Appium+python (3) element positioning (1)

Source: Internet
Author: User
Tags xpath appium

Open the uiautomatorviewer below the Ask price clip:

After the app in the night God Simulator, go back to Uiautomatorviewer:

Click on the device screenshot in the upper left corner, your night God simulator page will be displayed here, the right side is the corresponding positioning information, we mainly rely on the lower right corner of the node detail information to locate.

If you have the basis of selenium, then the introduction of the Basic agreement, just change a method:

    • Text

      find_element_by_name(u"视频")
    • Id

      find_element_by_resource-id("")
    • Class name

The view obtained by using ClassName is generally more than one, so you need to traverse the resulting views and then abbreviate the search criteria to get the target control

# 获取一个className下的所有控件
buttons = driver.find_elements_by_class_name("")
# 点击第一个元素
buttons.pop(0).click()
# 点击最后一个元素
buttons.pop().click()buttons.pop(-1).click()
    • Accessibility ID

This method belongs to the localization method of Appium extension.

In the content-desc corresponds to the accessibility_id

find_element_by_accessibility_id("")

-XPath

find_element_by_xpath("")

Android Uiautomator

# 注意,text里面必须是字符串,也就是说不能加u
find_element_by_android_uiautomator(‘new UiSelector().text("娱乐")‘)

In addition, there are

find_element_by_link_text()find_element_by_partial_link_text()find_element_by_tag_name()

Look at the code:

# Coding:utf-8

From AppiumImport Webdriver
From timeImport Sleepdesired_caps = {' PlatformName ':' Android ',
' devicename ': ' 127.0.0.1:62001 ',
                ' Platformversion ': '
                ' apppackage ': ' Com.tencent.news ',
                ' appactivity ': ' Com.tencent.news.activity.SplashActivity ',
                ' Unicodekeyboard ': True,
                ' Resetkeyboard ': True}driver = Webdriver. Remote ( "Http://localhost:4723/wd/hub", Desired_caps)
# Skip AD
Sleep ( 5)
# Position with text-click the video
Driver.find_element_by_name ( u "video"). Click ()
# Click to play
Driver.find_element_by_ Android_uiautomator ( ' new Uiselector (). Text ("Entertainment"). Click ()

The above code has two ways of positioning, in fact, before writing a lot of kinds, but it went to Chaos Point, is not to locate the location, such as I use the class positioning:

But the class of that row is the same, and cannot be positioned in the find_elements_by_classname () indexed way. Everyone also saw, I do not know why the text is not displayed, it seems that should be able to display, do not know where the problem

Positioning method There is an XPath, I am also very concerned about how to use this, but I do not know, but it seems that the above is almost ready for use case writing. As for XPath, see a lot of online said a bit not good, tube him, we do not manic, the next section we will introduce XPath.

Public search "automated test Practice" or scan the QR code below to add attention ~ ~ ~

Appium+python (3) element positioning (1)

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.