Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Predicate Queries Construction Rules

Mykola Mokhnach edited this page Nov 8, 2017 · 2 revisions

Purpose

Predicate queries are natively supported by XCTest and enable quick location of elements based on their attribute values.

Syntax

Follow the rules described in Predicate Format String Syntax article.

Available attributes

WebDriverAgent currently defines the following element attributes:

  1. name - The actual value of element's accessibility identifier or element's label if the first one is not set
  2. value - Element's value. It is always of type string (or nil if the value is not set) and contains the value of the corresponding element. Depending on the element's type this could be: a text or a placeholder text in the text field; a label of a text label; '1' or '0' if this is a checkbox or a switch
  3. label - Element's label value or nil if it is not present
  4. rect - Element's rectangle as a dictionary with the following keys: x, y, width, heigth
  5. type - Type string. All the possible element types are enumerated on this XCTest tutorial page.
  6. enabled - Whether the element is enabled or not (1/0)
  7. visible - Whether the element is displayed or not (1/0)
  8. accessible - Whether the element is accessible or not (1/0)
  9. accessibilityContainer - Whether the element is an accessibility container or not (1/0)

All these attribute names can be used in predicate queries also with wd prefixes, for example wdName.

Examples

type == 'XCUIElementTypeButton' AND value BEGINSWITH[c] 'bla' AND visible == 1 - find elements of type XCUIElementTypeButton whose value starts with Bla/bla/BLA and which are visible type IN {'XCUIElementTypeIcon','XCUIElementTypeImage'} AND visible == 1 - find all visible icons and images type == 'XCUIElementTypeCell' AND rect.width > 100 - find all cells whose width is greater than 100 type == 'XCUIElementTypeCheckBox' AND (visible == 1 OR enabled == 1) - find all check boxes, which are visible or enabled