Home » appium-tutorial » How to Use UISelector in Appium

Newly Updated Posts

How to Use UISelector in Appium

Previous Topic, In this tutorial we are going to learn How to Use UISelector in Appium.

UISelector is a class which implements the object class and provides different public method to locate or identify elements with different attribute or property values.

Note: In this tutorial we will discuss few of the most frequently used method in UISelector with syntex and for the rest of method will share their name(implementation is same for all) with its decription

How to Use MobileBy class with UISelector in Appium?

Below are the most used method:

1 ) className (String className): This method sets the criteria of matching the class name with in the code heirarcy with the name provided as a parameter.

driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().className(\"Enter the Class Name here\")"));
How to Use UISelector in Appium

2 ) resourceId(String id): This method search for the locator or inspect element from the code hierarchy on the basis of resourceId present first on the code.

//driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"Enter the resource Id here\")"));

3) text(String text): Search on the basis of text visible on the widget of the page.

//driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\"Enter the text here\")"));

4 ) packageName(String name): Search on the basis of package Name on the widget for the mobile application.

driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().packageName(\"Enter the package name here\")"));

5) decription(String desc): By providing the attribute value of content-description of the widget. We are good to locate or inspect the element.

driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().description(\"Enter the content-description here\")"));

6) instance(int instance): when we have element with similar property in that case we can identify or locate the element with the occurance of it instance no.The instance of an element is given by identifying element with common attribute followed by instance method.

driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().description(\"Enter the content-description here\")").instance(2));

7) index(int index): Search the widget on the basis of node index from layout.

driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"Enter the content-description here\")").index(2));

As we See above how UISelector works and defined with syntex, now we are going to list down few more methods below, their systex are same as we discussed above.

8) checkable(boolean value): It matches as search criteria with the current mobile window code hierarchy and looks if the element is checkable.

9) checked(boolean value): This method provides the search criteria in the widget to check that is checked.

10) clikable(boolean Value): This method checks whether the element is clikable.

Leave a comment

Your email address will not be published. Required fields are marked *