Appium+python Mobile Automation Test (iv)--monitor/uiautomatorviewer tool and element location method

Source: Internet
Author: User
Tags appium

Write in front:

This article describes the identification of the elements of the tools and elements of the positioning method, the tools to identify elements are mainly uiautomator and monitor, as well as Appium Inspector (small series under the windows in the 1.7.0 version can be used, 1.4.16 version is not available), This series of tutorials with the appium1.4.16 this article, it is not introduced Appium Inspector.

First, the common identification elements of the tool introduction

    1. Start Uiautomatorviewer.bat/monitor.bat. Open the Sdk/tools directory to find Uiautomatorviewer.bat/monitor.bat.

    2. Double-click to start after startup



Second, monitor connect mobile phone

    1. Win+r shortcut key input cmd Open, enter ADB devices, confirm the current device access.
    2. Open the main screen of the Magic Diffuse camera, click the Mobile robot icon in the Monitor interface, this button will refresh the latest interface every time

Third, positioning elements

    1. Move the mouse to the area of the element that you want to locate, and click to make the Red solid line box live. Click the button to enter the comics

      Node detail can see the attributes of the element
      Resource-id:com.manboker.headportrait:id/entry_album_set
      Class:android.widget.ImageView
      Used when the index interface has multiple identical properties

Four, click on my button

Navigate and click through Resource-id. The final code is as follows:

#Coding:utf-8Import Time fromAppiumImportWebdriverdesired_caps={}desired_caps['devicename'] ='192.168.199.101:5555'desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='5.0'desired_caps['Apppackage'] ='com.manboker.headportrait'desired_caps['appactivity'] ='com.manboker.headportrait.activities.FirstActivity'Driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps) time.sleep (8)#Sleep 8 secondsDRIVER.FIND_ELEMENT_BY_ID ('Com.manboker.headportrait:id/entry_album_set'). Click ()#点击进入我的页面driver.quit ()

Five, Appium tool simple use introduction

  1. Double-click Appium.exe to open, into the setting interface. The following 1 is the path of the APK being tested, 2 viewing the app's package name and launch activity,3 is the device name of the app under test.
  2. Open Appium
    Confirm the phone successful computer, click the triangle icon to the right of the search button to start the Appium service, when the interface appears as follows, the service has been started.
  3. Remote control (appium--general setting interface)

    Appium The default service address is the 127.0.0.1 port number 4723, which is normally debugged on the local machine without modification.
    if remote to an automated test computer to run this IP will come in handy, by modifying the following code can be
    Driver = Webdriver. Remote ('http://localhost:4723/wd/hub', Desired_caps)

    Change to:

    Driver = Webdriver. Remote ('http://192.168.0.105:4723/wd/hub', Desired_caps)

    As follows: Ipconfig view computer IP


  4. Remote connection
    Browser input: Http://192.168.0.105:4723/wd/hub, see the following interface to prove the success of the remote link
  5. The code in the script is modified as follows
    #Coding:utf-8Import Time fromAppiumImportWebdriverdesired_caps={}desired_caps['devicename'] ='192.168.199.101:5555'desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='5.0'desired_caps['Apppackage'] ='com.manboker.headportrait'desired_caps['appactivity'] ='com.manboker.headportrait.activities.FirstActivity'Driver= Webdriver. Remote ('Http://192.168.0.105:4723/wd/hub', Desired_caps) time.sleep (8)#Sleep 8 secondsDRIVER.FIND_ELEMENT_BY_ID ('Com.manboker.headportrait:id/entry_album_set'). Click () time.sleep (5) Driver.quit ()

Vi. element Positioning (common methods)

  1. Location by ID
    Take Resource-id value: driver.find_element_by_id (' Com.manboker.headportrait:id/entry_album_set ')
  2. Positioning via Class_name
    Take class content: Driver.find_element_by_class_name ("Android.widget.ImageView")
  3. Navigate through text
    Use the contents of text: Driver.find_elements_by_android_uiautomator ("New Uiselector (). Text (\" login \ ")")
  4. Positioning by name: Driver.find_element_by_name ()
  5. Positioning via XPath: Driver.find_element_by_xpath ("//android.widget.textview[@resource-id=\" Com.manboker.headportrait:id/ Nologin_retry\ "]")
  6. Positioning via Css_selector: Driver.find_element_by_css_selector ()
    As above, the Pycharm input driver.find_element_by will automatically match.

OK, this article describes this, the next article describes the Appium Python API.

Appium+python Mobile Automation Test (iv)--monitor/uiautomatorviewer tool and element location method

Related Article

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.