iOS Functions
This page lists the functions specific to iOS. These functions have an _i prefix in camel case, example: _iRotate. These functions will work only on an iOS device/simulator.
Action Functions
Section titled “Action Functions”_iTwoFingerTap
Section titled “_iTwoFingerTap”- Since
- Mobile Engine 7.5.0
Modes iOS
_iTwoFingerTap($element)Arguments
| Name | Type | Description |
|---|---|---|
$element | iOS Element | Element to be tapped. |
Returns
null |
Simulates two finger touches on an element, each with a single tap.
_iTwoFingerTap(_image("abc"));_iTapWithNumberOfTapsNumberOfTouches
Section titled “_iTapWithNumberOfTapsNumberOfTouches”- Since
- Mobile Engine 7.5.0
Modes iOS
_iTapWithNumberOfTapsNumberOfTouches($element, $taps, $touches)Arguments
| Name | Type | Description |
|---|---|---|
$element | iOS Element | element to be tapped |
$taps | integer | Number of taps |
$touches | integer | Number of touches. |
Returns
null |
Simulates number of finger touches on an element, each with a number of taps. NOTE that the first parameter is for taps and the second is for touches.
_iTapWithNumberOfTapsNumberOfTouches(_iMap(0), 2, 1); // One touch, with two taps. Same as _doubleClick_iTapWithNumberOfTapsNumberOfTouches(_iMap(0), 1, 2); // Two touches, each with a single tap. Same as _iTwoFingerTap_iRotate
Section titled “_iRotate”- Since
- Mobile Engine 7.5.0
Modes iOS
_iRotate($element, $rotationAngle, $velocity)Arguments
| Name | Type | Description |
|---|---|---|
$element | iOS Element | Element to be rotated |
$rotationAngle | float | Rotation of the gesture in radians. A positive value indicates a clockwise rotation. A negative value indicates counter clockwise rotation. |
$velocity | float | Velocity of the rotation gesture in radians per second. If rotationAngle is negative, then velocity must be negative. |
Returns
null |
Simulates a rotation gesture on an element.
_iRotate(_iMap(0), Math.PI/4, 0.5); // Clockwise rotation_iRotate(_iMap(0), -Math.PI/4, -0.5); // Counter-clockwise rotation_iActivateSiriWithVoiceRecognitionText
Section titled “_iActivateSiriWithVoiceRecognitionText”- Since
- Mobile Engine 7.5.0
Modes iOS
_iActivateSiriWithVoiceRecognitionText($text)Arguments
| Name | Type | Description |
|---|---|---|
$text | string | Text to be recognized. |
Returns
null |
Activates Siri with voice recognition text.
Works only on iOS devices/simulators with iOS version greater than iOS 10.3.
_iActivateSiriWithVoiceRecognitionText("Please set a reminder for my meeting with John");_iPressVolumeUp
Section titled “_iPressVolumeUp”- Since
- Mobile Engine 7.5.0
Modes iOS
_iPressVolumeUp()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
Simulates volume up action on an iOS Device.
Works only on an iOS device, and not on an iOS simulator.
_iPressVolumeUp();_iPressVolumeDown
Section titled “_iPressVolumeDown”- Since
- Mobile Engine 7.5.0
Modes iOS
_iPressVolumeDown()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
Simulates volume down action on an iOS Device.
Works only on an iOS device, and not on an iOS simulator.
_iPressVolumeDown();Fetch Functions
Section titled “Fetch Functions”_iIsSelected
Section titled “_iIsSelected”- Since
- Mobile Engine 7.5.0
Modes iOS
_iIsSelected($element)Arguments
| Name | Type | Description |
|---|---|---|
$element | iOS Element | Element whose isSelected attribute is to be checked. |
Returns
boolean | true or false based on whether the element is selected or not. |
Returns true if the element is selected. Otherwise, returns false.
var $selected = _iIsSelected(_button("radio-button"));_iIsDevice
Section titled “_iIsDevice”- Since
- Mobile Engine 7.5.0
Modes iOS
_iIsDevice()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
boolean | true or false based on whether the running platform is an iOS device. |
Returns true if the running platform is an iOS device. Returns false for an iOS simulator.
if (_iIsDevice()) { // Volume down can be simulated only for an iOS device. _iPressVolumeDown();}_iGetApplicationState
Section titled “_iGetApplicationState”- Since
- Mobile Engine 7.5.0
Modes iOS
_iGetApplicationState($bundleId)Arguments
| Name | Type | Description |
|---|---|---|
$bundleId | iOS App Bundle Id | Bundle id of application whose state is required.Element whose isSelected attribute is to be checked. |
Returns
boolean | State of application as number. |
Returns state of application.
var $state = _iGetApplicationState("com.sahipro.ios.test.SahiTestApp");System Dialog Functions
Section titled “System Dialog Functions”In iOS, system dialogs cannot be automated with regular APIs. For example, one cannot use _click to click on the Allow button in a system dialog.
Refer to Automating System Dialogs for details on how to automate a system dialog.
_iExpectSystemDialog
Section titled “_iExpectSystemDialog”- Since
- Mobile Engine 7.5.0
Modes iOS
_iExpectSystemDialog($message, $buttonIdentifier[, $persist])Arguments
| Name | Type | Description |
|---|---|---|
$message | string | Message to expect in dialog. This can also be a regular expression |
$buttonIdentifier | string|integer | Sahi Identifier for the button. Can also be just an index. |
$persist | booleanoptional | If true, will accept a single _iExpectSystemDialog statement for all system dialogs coming after the statement. If false, will accept only the next system dialog to work with the _iExpectSystemDialog statement. Default is false. |
Returns
null |
_iExpectSystemDialog tells Sahi to click the button with the given buttonIdentifier, for a dialog with given message.
var $dialogLabelExpected = "/Allow.*Maps.*location/";var $btnTextToClick = "Allow"; // This will click the "Allow" button
// Set the expected dialog label, and indicate the button to click._iExpectSystemDialog($dialogLabelExpected, $btnTextToClick);_iInteractWithApp
Section titled “_iInteractWithApp”- Since
- Mobile Engine 7.5.0
Modes iOS
_iInteractWithApp()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
For iOS to invoke the system dialog handler, the app has to be interacted with. _iInteractWithApp() does just that.
_iInteractWithApp();_iLastSystemDialog
Section titled “_iLastSystemDialog”- Since
- Mobile Engine 7.5.0
Modes iOS
_iLastSystemDialog([$alldialogs])Arguments
| Name | Type | Description |
|---|---|---|
$alldialogs | booleanoptional | If true, returns array of all system dialog messages. |
Returns
string | last system dialog message if $alldialogs is false |
array of strings | an array of all dialog messages in the browser if $alldialogs is true |
// Return array of all system dialog messages.var $allMessages = _iLastSystemDialog(true);// Return only last system dialog message.var $lastMessage= _iLastSystemDialog();_iClearLastSystemDialog
Section titled “_iClearLastSystemDialog”- Since
- Mobile Engine 7.5.0
Modes iOS
_iClearLastSystemDialog()Arguments
| Name | Type | Description |
|---|---|---|
None |
Returns
null |
Removes the last system dialog message from session so that further occurrence of system dialogs can be checked
_iClearLastSystemDialog();System Dialog Example
Section titled “System Dialog Example”var $dialogLabelExpected = "/Allow.*Maps.*location/";var $btnTextToClick = "Allow";
// Set the expected dialog label, and indicate the button to click._iExpectSystemDialog($dialogLabelExpected, $btnTextToClick);
// Activate the Maps application_mActivateApplication("com.apple.Maps", true);// Wait a little while so that the system dialog comes up._wait(3000);
// IMPORTANT: Interact with the app. This is what will trigger the dialog handler._iInteractWithApp();// Sahi would click on the Allow button now.
// Get the last dialog label and assert that it is same as expected.var $dialogLabelActual = _iLastSystemDialog();_assertEqual($dialogLabelExpected, $dialogLabelActual);Other Functions
Section titled “Other Functions”_iSetAutoDismissKeyboard
Section titled “_iSetAutoDismissKeyboard”- Since
- Mobile Engine 8.0.0
Modes iOS
_iSetAutoDismissKeyboard($autoDismiss)Arguments
| Name | Type | Description |
|---|---|---|
$autoDismiss | boolean | true or false |
Returns
null |
By default, Sahi will try to dismiss keyboard automatically after setting value in the textfield. To disable this functionaity set it to false.
Sahi will try to click on the keyboard button provided by ios.keyboard.buttons.autoclick property in SAHI_INSTALL_PATH\config\sahi.properties.

