new UiElement()
Represents a single UI element on an Android device screen.
The UiElement class is the core object returned by UiElement.findObject() or UiSelector.findOne().
It allows direct interaction with a UI node (e.g., button, text field, checkbox) including:
- reading attributes like
text,bounds,resource-id, etc. - performing actions like
clickSync(),longClickSync(),setText(),screenshot() - retrieving and updating node info via accessibility engine (AAI)
Most interactions are performed by sending AAI commands to the associated device,
making this class suitable for precise, scriptable UI automation.
Typical Usage
var obj = UiElement.findObject(device, "T:Submit");
obj.clickSync();
var text = obj.getText();
obj.setText("Updated");
obj.screenshot("output.bmp");
Members
click2Sync
similar to click() except it will randomly click inside the bounds of the node.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.findObject(sigmaDevice, query);
obj.click2Sync()
clickSync
similar to device.clickSync, it will click in the middle of bounds on the specific component.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.findObject(sigmaDevice, query);
obj.clickSync()
getBounds
Gets the bounds of the UI element. as "[left, top][right, bottom]".
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getBounds()
getChildCount
Gets the child element count of the UI element.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getChildCount()
getClassName
Gets the class name of the UI element.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getClassName()
getDescription
Gets the description content of the UI element (with auto update).
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getDescription()
getId
Capture screenshots for all UI elements in the array and save to PC.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
var obj = UiElement.findObject(sigmaDevice, "T:Text Message");
obj.getId();
getInputType
Gets the input type of the UI element.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getInputType()
getName
similar to device.getName, it will get device name.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.findObject(sigmaDevice, query);
obj.getName()
getPackageName
Gets the package name of the UI element.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getPackageName()
getResourceId
Gets the resource ID of the UI element.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getResourceId()
getText
Gets the visible text of the UI element (with auto update).
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, "T:Text Message");
obj.getText()
longClickSync
hold and click longer (500ms) to simulate a long click.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.findObject(sigmaDevice, query);
obj.longClickSync()
screenshot
Save the image on the node bounds to PC.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.findObject(sigmaDevice, query);
obj.screenshot(<file path>, <image type>)
screenshotToDevice
Save the image on the node bounds to device.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.findObject(sigmaDevice, query);
obj.screenshotToDevice(<file path>, <image type>)
setText
set the text to the text field.
Example
var { Device } = require("sigma/device");
var { UiElement } = require("sigma/aai");
var sigmaDevice = Device.getMain();
// Define the UiElement object as obj
var obj = UiElement.Object(sigmaDevice, query);
obj.setText(text)