Appium Concise Tutorial (11)--Using resource ID to locate

Source: Internet
Author: User
Tags appium

The previous ethanol band has been known about Appium's positioning strategy. In fact, the Appium control is positioned in full compliance with the Webdriver Mobile extension protocol.

This section will share how to use the resource ID to locate the Android policy.

What is resource ID, this does not belong to the scope of this article, you can click here to understand.

There are two ways we can use the resource ID to locate:

    • Use the findelement (by.id ("ResourceId")) method. This is also the original Webdriver definition of the method, but unexpectedly in the official document of Appium not mentioned, belonging to the hidden technology;

    • Use find_elements_by_android_uiautomator ('new Uiselector (). ResourceId ("the_id")') the following tutorial on Uiautomator positioning will be explained;

As you can see from the code snippet above, it is easiest to locate using find_element_by_id .

So how to get the resource ID of the control, use Uiautomatorviewer. The exact method is as shown.

Now take the example of the Android native Calculator program shown, and see how each language is implemented by clicking the "9" button.

Objective

Click on the "9" button on the calculator. The ID of the button is com.android.calculator2:id/digit6 . First sweet and bitter, starting with Ruby.

The copyright of this article is owned by ethanol, welcome reprint, but please specify the author and source, strictly prohibited for any commercial use

Ruby article
Require'Appium_lib'caps= {caps: {platformname:'Android', appactivity:'. Calculator', Apppackage:'Com.android.calculator2'}, Appium_lib: {sauce_username:nil, Sauce_access_key:nil, debug:true}}dr=Appium::D river.new (Caps). Start_driverdr.find_element (ID:'Com.android.calculator2:id/digit9'). Click

Python article
#Coding:utf-8 fromAppiumImportWebdriver fromTimeImportSleepdesired_caps={}desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='4.4'desired_caps['devicename'] ='Android Emulator'desired_caps['app'] ='calculator.apk'desired_caps['Apppackage'] ='Com.android.calculator2'desired_caps['appactivity'] ='. Calculator'Dr= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps) sleep (3) dr.find_element_by_id ('Com.android.calculator2:id/digit9'). Click ()

Java Chapter
//Create a new FindByID class located under the Info.itest.www package Packageinfo.itest.www;Importio.appium.java_client. Appiumdriver;Importjava.net.MalformedURLException;ImportJava.net.URL;ImportOrg.openqa.selenium.remote.CapabilityType;Importorg.openqa.selenium.remote.DesiredCapabilities; Public classFindByID { Public Static voidMain (String args[])throwsmalformedurlexception {desiredcapabilities cap=Newdesiredcapabilities (); Cap.setcapability (Capabilitytype.browser_name,""); Cap.setcapability ("PlatformName", "Android"); Cap.setcapability ("DeviceName", "Android Emulator"); Cap.setcapability ("Platformversion", "4.4"); Cap.setcapability ("Apppackage", "Com.android.calculator2"); Cap.setcapability ("Appactivity", ". Calculator "); Appiumdriver Dr=NewAppiumdriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), CAP); Dr.findelement (By.id ("Com.android.calculator2:id/digit9") . Click (); }}

If the reader is familiar with Webdriver, then mastering this method is very simple. If you are not familiar with Webdriver, then you can refer to the Webdriver Practical Guide to ethanol, first learn the basic knowledge of webdriver.

In this section we have written some scripts to navigate the controls, and in actual projects these scripts without any assertions are basically unable to complete the function of the test case.

The next section of ethanol will lead you to write the first appium test case.

The copyright of this article is owned by ethanol, welcome reprint, but please specify the author and source, strictly prohibited for any commercial use

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.