Find elements for native apps

When using the AppiumDriver findElementByXXX() methods or findElement(By) method, the Perfecto Appium integration translates this to a findElementByXpath(). The following table shows the XPath expressions used to find elements in native apps.

By XPath
accessibilityId //*[@content-desc="id" or @name="id" or @label="id"]
className //className or //*[@class="className"]
cssSelector not supported
id //*[@resource-id="id" or @label="id"]
linkText not supported
partialLinkText not supported
name //*[@name="name" or @text="name"]
tagName not supported
xpath supported *
iosUIAutomation supported
androidUIAutomator supported

* iOS XPath limitations

Supported attributes

  • name, label, value, enabled, valid, visible, path, x, y, width, height

Unsupported attributes

  • dom

Limitations

  • Integer value for attributes: x, y, width, height
  • UIAApplication element contains only the path attribute

Android XPath limitations

  • Hierarchy rotation attribute is not supported
  • NAF attribute is not supported.

Example

Copy
driver.findElements(By.className("android.widget.CheckBox"));

translates to

Copy
driver.findElementsByXpath("//android.widget.CheckBox or //*[@class='android.widget.CheckBox']");