Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Oct 22, 2017 09:38

 

(This article refers to XCUItest automation via Appium for iOS devices according to this document)

 

Writing Appium scripts usually involves performing operations on elements.

Dependent upon the UI layout that we are currently testing, element operations might be heavy in terms of execution time and performance.

There are a few ways to enhance these operations. In this article we will suggest another way to locate (find) an element which significantly improves the performance and shortens the execution time.

 

The common way to locate an element is based on the ‘find by XPath’ method (findByXpath). Behind the scenes, this method performs the following actions:

  1. Go over all of the elements on (and out of) the screen.
  2. For each element - get all attributes (text, class, name, enabled, visible, hittable, height, width, x, y, identifier, type) .
  3. Create the UI Elements tree, including all elements, as a valid XML  (by hierarchy).
  4. Evaluate the given XPath on the UI Elements tree XML.

 

Possible response for this kind of find operation:

  • “element not found”
  • “single element found”
  • “multiple elements found”.

 

 

Recommended, better way is to use ‘find by identifier’.

Behind the scenes, this method performs the following actions:

  1. Go over elements on (and out of) the screen
  2. For each element, retrieve only the ‘identifier’ attribute.
  3. Stop searching when a match is found.

 

Possible response for this kind of find operation:

  • “element not found”
  • “single element found”.

 

 

Find by identifier advantages:

-      Identifier is unique and permanent. (XPath not always unique and depends on many variables)

-      Significantly Faster!!! Locating by identifier is much faster operation for each element and traverses fewer elements.  

 

Find by identifier disadvantages:

-      Not every element has an identifier declared (depends on the specific application implementation).

 

 

How to use it?

 

 

 

As shown in the screenshot, an image of a bed is selected.

 

Use the following Appium command to find a UI element using identifier (use the value for the attribute ‘identifier’):

"driver.findElementsByAccessibilityId("sleepOnboardBegin")"