Finding elements with uiautomatorviewer

uiautomatorviewer is one of tool in android sdk packages, you can find it under <ANDROID_HOME>/tools folder:

Screen Shot 2017-04-04 at 4.28.54 PM.png

To open uiautomatorviewer you need to double click on it or type command uiautomtorviewer in windows commandline:

Screen Shot 2017-04-04 at 4.30.08 PM

Now you can going to take example with android calculator app by following steps below:

Step 1: open android simulator or real device

Step 2: open calculator app

Step 3: click on the devices’s screenshot (Screen Shot 2017-04-04 at 4.36.09 PM) button from UiAutomatorVier:

Screen Shot 2017-04-04 at 4.39.03 PM

Finding elements by ID

In case you want to locate android elements by ID, you need find the resource-id value of its.

by_id

here is java code to locate button number 5 via id

driver.findElement(By.id("com.android.calculator2:id/digit_5"))

Finding elements by NAME

With the button 5 above, when locate it with name is mean use text property

by_name.png

driver.findElement(By.name("5"));

Finding elements by CLASSNAME

by_class

driver.findElement(By.className("android.widget.Button"))

Finding elements by ACCESSIBILITY ID

If you want use this way, please get value of content-desc:

by_accessibility_id.png

driver.findElementByAccessibilityId("divide");

Finding elements by ANDROIDUIAUTOMATOR

With the button 5 above, when locate it with android UiAutomator method:

driver.findElementByAndroidUIAutomator("new UiSelector().resourceId(\"com.android.calculator2:id/digit_5\")");

Finding elements by XPATH

driver.findElement(By.xpath(".//android.widget.Button[4]"));
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s