new UiSelector(device) → {UiSelector}
A chainable selector for building advanced UI queries to identify UiElement objects on Android device screens.
UiSelector provides a fluent API to construct AAI-compatible query strings based on:
- text (
.text("OK")) - description (
.descriptions("Settings")) - resource ID (
.idEndsWith("btn_submit")) - class name, package name, and more
Once the query is defined, use .findOne() to execute and retrieve a UiElement object.
Typical Usage
var selector = new UiSelector(device);
var obj = selector.text("Submit").idEndsWith("btn").findOne();
if (obj) obj.clickSync();
How to use UiSelector:
- Create UiSelector (ui selector) object
- Call UiSelector method to set matching conditions
- Execute the set selector (by calling the findOne() method)
- Return a UiElement object after successful execution
Example
// Example: Click the UI element whose text is "Total Control" and resource-id ends with "test"
var { Device } = require("sigma/device");
var { UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
var ret = uiSelector.text("Total Control").idEndsWith("test").findOne();
if (ret) {
ret.clickSync(); // Execute click if element is found
} else {
print("Total Control not found");
}
// Operation Result:
// If the element is found and `clickSync()` is executed:
Execute click event
// If not found:
Total Control not found
Parameters:
| Name | Type | Description |
|---|---|---|
device |
Device | The target device object obtained via |
Returns:
After calling UiSelector related methods, return a UiSelector object after setting
After executing the UiSelector that has been set, return a UiElement object
- Type
- UiSelector
Members
className
Set the matching condition parameter to the class name of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.className(string)
classNameContains
Set the matching condition parameter to the class name containing string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.classNameContains(string)
classNameEndsWith
Set the matching condition parameter to the class name ending in string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.classNameEndsWith(string)
classNameStartsWith
Set the matching condition parameter to the class name starting with string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.classNameStartsWith(string)
descContains
Set the matching condition parameter to include the description content of the string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.descContains(string)
descEndsWith
Set the matching condition parameter to the description content at the end of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.descEndsWith(string)
descStartsWith
Set the matching condition parameter to the description content at the beginning of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.descStartsWith(string)
descriptions
Set the matching condition parameter to the description content of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.descriptions(string)
findOne
Execute the UiSelector selector that has been set, and return a UiElement object
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.findOne()
id
Set the source id content of the matching condition parameter to string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.id(string)
idContains
Set the matching condition parameter to the source id content containing string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.idContains(string)
idEndsWith
Set the matching condition parameter to the source id at the end of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.idEndsWith(string)
idStartsWith
Set the matching condition parameter to the Resouce id content at the beginning of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.idStartsWith(string)
packageName
Set the matching condition parameter to the package name of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.packageName(string)
packageNameContains
Set the matching condition parameter to the package name containing string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.packageNameContains(string)
packageNameEndsWith
Set the matching condition parameter to the package name ending in string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.packageNameEndsWith(string)
packageNameStartsWith
Set the matching condition parameter to the package name starting with string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.packageNameStartsWith(string)
text
Set the matching condition parameter to the text content of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.text(string)
textContains
Set the matching condition parameter to include string text content
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.textContains(string)
textEndsWith
Set the matching condition parameter to the text content at the end of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.textEndsWith(string)
textStartsWith
Set the matching condition parameter to the text content at the beginning of string
Example
var { Device } = require("sigma/device");
var { UiElement, UiSelector } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var uiSelector = new UiSelector(sigmaDevice);
uiSelector.textStartsWith(string)