Fetch APIs
abstract
While working on scripts, we often need to fetch content from the application screen.
Examples may be:
Examples may be:
- Fetching and storing a generated userId for later use in script
- Getting the value of form field for verification
- Getting the text from a UI element for assertion
- Getting some particular attribute of a UI element, like href of a link
_getValue
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.0.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_getValue($element)
Arguments
$element | HTML DOM element | Form element whose value we need |
Returns
string | Value of the element |
Sahi Pro Flowcharts Action :Get Value
Details
For getting text out of div or span like elements, use _getText
info
This API only works on elements which take user text input.
// Using in an assertion
_assertEqual("Tyto", _getValue(_textbox("company")));
// Fetching and storing value
var $userId = _getValue(_textbox("userId"));
For getting text out of div or span like elements, use _getText
_getText
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.0.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_getText($el)
Arguments
$el | HTML DOM element | Element whose text we need |
Returns
string | Text content of the element |
Sahi Pro Flowcharts Action :Get Text
Details
The returned string is normalized for different browsers. Multiple continuous spaces are replaced with single space.
Multiple continuous newlines are replaced with single newline. Newlines are always returned as \n even on
Mac and Linux, so that scripts can work across browsers and OSes.
This API uses the textContent or innerText attributes of elements.
The returned string is normalized for different browsers. Multiple continuous spaces are replaced with single space.
Multiple continuous newlines are replaced with single newline. Newlines are always returned as \n even on
Mac and Linux, so that scripts can work across browsers and OSes.
This API uses the textContent or innerText attributes of elements.
// Using in an assertion
_assertEqual("Tyto", _getText(_div("companyDiv")));
// Fetching and storing value
var $userId = _getText(_div("userIdDiv"));
_datalistFilter
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
9.2.0 | NA | NA | NA | NA |
Available for modes: Browser
_datalistFilter($el[, $filter])
Arguments
$el | HTML DOM element | Input or datalist element |
$filter | string optional | Data to filter (case-insensitive). |
Returns
HTML DOM element |
Sahi Pro Flowcharts Action :Datalist Filter
Details
Specifies the filter data on input element which filters the list. This api should be used with _getOptions. Eg.
Specifies the filter data on input element which filters the list. This api should be used with _getOptions. Eg.
_getOptions(_datalistFilter(_datalist("country_list"), "ind"));
returns array with all options matching with "ind" in the list.
_getOptions
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | 7.5.0 | NA | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | SAP
_getOptions($el[, $type])
Arguments
$el | HTML DOM element | Select/ Input or associated datalist to the input element |
$type | string optional | Type can be specified as "value" or "text".
If the type is specified as "text" then text contents of all the options are returned. If the type is specified as "value" then values of all the options are returned. If the type is not specified then text contents of all the options are returned. |
Returns
array of strings | Array containing the values or texts of all options of the select or datalist element |
Sahi Pro Flowcharts Action :Get Options
Details
If we want the values of all the options of the selectbox:
If we want the values of all the options of the selectbox:
var $list = _getOptions(_select("select_id"), "value");
_assertEqual("Value of First Option", $list[0]);
_assertEqual("Value of Second Option", $list[1]);
_assertEqual(2, $list.length);
For getting visible text of all options:
var $list = _getOptions(_select("select_id"));
_assertEqual("Visible Text of First Option", $list[0]);
_assertEqual("Visible Text of Second Option", $list[1]);
_assertEqual(2, $list.length);
For getting text or values for datalist(datalist support is only available from Sahi Pro v9.2.0):
var $list = _getOptions(_datalist("country_list"));
_assertEqual(["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa"], $list);
$list = _getOptions(_textbox("country"), "text");
_assertEqual(["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa"], $list);
For getting filtered text or values for datalist using _datalistFilter:
var $list = _getOptions(_datalistFilter(_datalist("country_list"), "AL"));
_assertEqual(["Aland Islands", "Albania", "Algeria"], $list);
$list = _getOptions(_datalistFilter(_textbox("country"), "AL"), "text");
_assertEqual(["Aland Islands", "Albania", "Algeria"], $list);
_getCellText
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_getCellText($el)
Arguments
$el | HTML DOM element | Cell (TD) element whose text we need |
Returns
string | Text content of the cell element |
Sahi Pro Flowcharts Action :Get Cell Text
Details
Returns the text content as a string
Returns the text content as a string
dangerDEPRECATED:
Use
_getText(element)
instead.
_getSelectedText
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.0.0 | NA | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | SAP
_getSelectedText($el)
Arguments
$el | HTML DOM element | Select dropdown element whose selected text we need |
Returns
string | Text content of the selected option of a select dropdown |
Sahi Pro Flowcharts Action :Get Selected Text
Details
Returns the text of the selected option in a select dropdown box.
Returns the text of the selected option in a select dropdown box.
// Using in an assertion
_assertEqual("18", _getSelectedText(_select("legalAge")));
// Fetching and storing value
var $legalAge = _getSelectedText(_select("legalAge"));
warning
_getSelectionText returns the text that the user has selected on a page.
_getSelectionText returns the text that the user has selected on a page.
_getAttribute
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.5.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java (8.0.0) | Android | iOS | SAP
_getAttribute($el, $attributeName)
Arguments
$el | HTML DOM element | Element whose attribute we need |
$attributeName | string | The attribute to be fetched |
Returns
string | The attribute value |
Sahi Pro Flowcharts Action :Get Attribute
Details
Returns the specified attribute's value for the element.
Returns the specified attribute's value for the element.
// Using in an assertion
_assertEqual("http://sahi.co.in/", _getAttribute(_link("Home"), "href"));
// Fetching and storing value
var $href = _getAttribute(_link("Home"), "href");
warning
Some attributes may have different names in javascript and HTML. Always use the javascript attribute name.
For example,
the
the
Fortunately there are not many such differences.
For example,
the
class
attribute in HTML is accessed as className
in javascript
the
for
attribute of labels in HTML is accessed as htmlFor
in javascript
Fortunately there are not many such differences.
_exists
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.0.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_exists($el)
Arguments
$el | HTML DOM element | Element to check |
Returns
boolean | true if element exists on the page, else false |
Sahi Pro Flowcharts Action :Exists
Details
It checks for existence of the element in the application. However, note that elements may exist but not be visible on the user interface.
It checks for existence of the element in the application. However, note that elements may exist but not be visible on the user interface.
infoFor testing, _isVisible is a better check than _exists.
infoFor testing,
Is Visible
Action is a better check than Exists
Action.// Using in an assertion
_assertTrue(_exists(_link("Home")));
// same as
_assertExists(_link("Home")));
// Fetching and storing value
var $exists = _exists(_link("Home"));
_areEqual
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | 7.5.0 | NA | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | SAP
_areEqual($expected, $actual)
Arguments
$expected | any | Expected value.
This value can be any normal javascript data type or an array Regular expressions can also be used. (eg. "/del/") |
$actual | any | Actual value.
This value can be any normal javascript data type or an array. It is mostly some attribute of a HTML DOM element. |
Returns
boolean | true if the expected and actual values match, else false |
Sahi Pro Flowcharts Action :Are Equal
Details
Compares two Javascript data type or arrays.
Compares two Javascript data type or arrays.
// Compare string with regular expression.
var $compare1 = _areEqual("/^a.*c$/", "abc"); // $compare1 is true.
// Compare text of an element with regular expression.
var $compare2 = _areEqual("/created/", _getText(_div("result")));
// Compare arrays.
$exp = [/[a-z]+$/, "b"];
$act = ["ab", "b"];
var $compareArr = _areEqual($exp, $act); // $compareArr is true.
info
_assertEqual allows a regular expression in the expected value. But it cannot be used in an if condition.
Instead one could use _areEqual in the if condition to execute the desired code and _assert(false) can be used in the else block to indicate failure.
The advantage of using _areEqual instead of a direct equal to (==) comparison is that _areEqual allows the use of regular expression in the expected value.
Instead one could use _areEqual in the if condition to execute the desired code and _assert(false) can be used in the else block to indicate failure.
The advantage of using _areEqual instead of a direct equal to (==) comparison is that _areEqual allows the use of regular expression in the expected value.
_isVisible
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.0.0 | 7.5.0 | 9.0.0 | 10.0.0 |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_isVisible($el[, $checkZIndex[, $doScroll]])
Arguments
$el | HTML DOM element | Element to check |
$checkZIndex | boolean optional | If true, checks whether the element is on top or not(Checks whether some other element with a higher Z index is not hiding it). If false, omits this check.
Default is false. |
$doScroll | boolean optional | If true, checks whether element is the top element by scrolling to the element. If false, checks only for the current viewport.
Default is false. Used only when checkZIndex is true. |
Returns
boolean | true if element is visible, else false |
Sahi Pro Flowcharts Action :Is Visible
Details
info
In 6.0.0, $checkZIndex and $doScroll have been newly added. Scripts written before 6.0.0 do NOT need changes.
// Using in an assertion
_assertTrue(_isVisible(_link("Home"))); // doesn't check z-index
_assertTrue(_isVisible(_link("Home"), true)); //checks z-index
_assertTrue(_isVisible(_link("Home"), true, true)); //checks z-index after scrolling
// Fetching and storing value
var $visible = _isVisible(_link("Home"));
_isChecked
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
7.0.0 | 7.0.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS (8.0.0) | SAP
_isChecked($el)
Arguments
$el | HTML DOM element | Element to check |
Returns
boolean | true if element is checked, else false |
Sahi Pro Flowcharts Action :Is Checked
Details
Returns true if the element is checked. This is applicable for radio buttons and checkboxes.
Returns true if the element is checked. This is applicable for radio buttons and checkboxes.
// Using in an assertion
_assertTrue(_isChecked(_radio("Male")));
_isEnabled
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
7.5.0 | 7.5.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_isEnabled($element)
Arguments
$element | element | element to be check |
Returns
boolean | true if element is enabled, else false |
Sahi Pro Flowcharts Action :Is Enabled
Details
Some elements in your application could be disabled. This API returns true if the specified element is enabled.
Some elements in your application could be disabled. This action returns true if the specified element is enabled.
// Using in an assertion
_assertTrue(_isEnabled(_button("Download")));
_containsText
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.5.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java (8.0.0) | iOS | SAP
_containsText($element, $text)
Arguments
$element | el | Element where we need to check if text is present |
$text | string | Text to check for. Can also be a regular expression |
Returns
boolean | true if element contains the text, else false |
Sahi Pro Flowcharts Action :Contains Text
Details
Returns true if the element contains the specified text.
Returns true if the element contains the specified text.
<div id="d1" style="background-color:yellow"><i>Formatted</i> Text</div>
_containsText(_div("d1"), "Formatted") //=true
_containsText(_div("d1"), "Text") //=true
_containsText(_div("d1"), "Formatted Text") //=true
_containsText(_div("d1"), "/Format.*Text/") //=true
_containsText(_div("d1"), "/mat.*Te/") //=true
_containsText(_div("d1"), "Non existent") //=false
_containsHTML
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_containsHTML($element, $html)
Arguments
$element | el | Element where we need to check if text is present |
$html | string | HTML to check for. Can also be a regular expression |
Returns
boolean | true if element contains the HTML, else false |
Sahi Pro Flowcharts Action :Contains HTML
Details
Returns true if the element contains the specified HTML content.
Returns true if the element contains the specified HTML content.
<div id="d1" style="background-color:yellow"><i>Formatted</i> Text</div>
_containsHTML(_div("d1"), "<i>Formatted</i>") //=true
_containsHTML(_div("d1"), "Text") //=true
_containsHTML(_div("d1"), "<i>Formatted</i> Text") //=true
_containsText(_div("d1"), "/<i>.*</i> Text/") //=true
_containsHTML(_div("d1"), "Formatted Text") //=false
_containsHTML(_div("d1"), "Non existent") //=false
_contains
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.5.0 | NA | NA | NA |
Available for modes: Browser | Windows | Java (8.0.0)
_contains($parent, $child)
Arguments
$parent | HTML DOM element | Parent element |
$child | HTML DOM element | Child element |
Returns
boolean | true if the specified child element is a child of the specified parent element, else false |
Sahi Pro Flowcharts Action :Contains
Details
<div id="d1">
<span>inside</span>
</div>
_contains(_div("d1"), _span("inside")) //=true
_title
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_title()
Arguments
None |
Returns
string | Title of the top most page (the title visible on the browser) |
Sahi Pro Flowcharts Action :Title
Details
var $title = _title(); // returns "Sahi Pro - Fetch APIs" for this page.
_getTableContents
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | 8.0.0 | NA | NA | NA |
Available for modes: Browser | Java
_getTableContents($tableEl[, $columns[, $rows[, $count]]])
Arguments
$tableEl | HTML DOM element | Table element |
$columns | array of objects optional | Array of column identifiers. The identifiers can be index, text or regular expression of text |
$rows | string|integer|array of integers optional | Can be a regular expression, an array of indexes or the starting index |
$count | integer optional | If rows is the starting index, count is the ending index, If rows is a regular expression, count is the total count. If rows is an array of indexes, count is ignored. |
Returns
two dimensional array of strings | The data from the table |
Sahi Pro Flowcharts Action :Get Table Contents
Details
// All table data
var $data = _getTableContents(_table("tableId"));
// All rows, but only specific columns from the table
var $data = _getTableContents(_table("tableId"), [1,3,7] );
// Returns all rows with columns 2, 4 and 8 since index is 0 based.
// All rows, but only specific columns from the table
var $data = _getTableContents(_table("tableId"), [1,"Price", "/Stock/"] );
// Returns all rows with column 2 (index is 0 based), column with header "Price" and column header matching regular expression /Stock/
// Rows containing specified keyword, but only specific columns from the table
var $data = _getTableContents(_table("tableId"), ["Price", "/Stock/"], "/pen/" );
// Returns all rows containing words matching regular expression /pen/, with columns having column header Price and column header matching
// regular expression /Stock/. Note that /pen/ is matched with all the columns of the row.
// First n rows containing specified keyword, but only specific columns from the table
var $data = _getTableContents(_table("tableId"), ["Price", "/Stock/"], "/pen/", 8);
// Returns first 8 rows contain words matching regular expression /pen/ having column header Price and column header matching
// regular expression /Stock/
// Rows having indexes specified in array, with specific columns from the table
var $data = _getTableContents(_table("tableId"), ["Price", "/Stock/"], [3,4,7]);
// Returns rows 4, 5 and 8 (index is 0 based) having all columns with header "Price" and column header matching regular expression /Stock/
// Rows from m to n, but only specific columns from the table
var $data = _getTableContents(_table("tableId"), ["Price", "/Stock/"], 3, 7 );
// Returns rows from 3 to 7 having all columns with header "Price" and column header matching regular expression /Stock/
info
Prefer using _getTableContents to _collect or _collectAttributes, if you specifically need the contents of an html table (as against other collections) and you need to get the content of many such tables in a script.
_style
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_style($el, $styleAttribute)
Arguments
$el | HTML DOM element | element whose style attribute we need |
$styleAttribute | string | style attribute to be fetched |
Returns
string | The style attribute value |
Sahi Pro Flowcharts Action :Style
Details
info
Styles in HTML elements are calculated by the browser based on various CSS rules.
_style returns the computed style that is finally applicable to the element.
Accessing style directly as an attribute will not give computed style.
Always use _style instead.
_style returns the computed style that is finally applicable to the element.
Accessing style directly as an attribute will not give computed style.
Always use _style instead.
// Using in assertion
_assertEqual("24px", _style(_heading1(0), "font-size"));
// Fetching and storing value
var $fontSize = _style(_heading1(0), "font-size");
_position
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.5.0 | 7.5.0 | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | Android | iOS | SAP
_position($el[, $relative])
Arguments
$el | HTML DOM element | element whose position we need |
$relative | boolean optional | If true, returns position relative to current viewport.
Default is false. |
Returns
array of integers | An array [x,y] of the elements position in pixels relative to its window/frame/iframe |
Sahi Pro Flowcharts Action :Position
Details
This may be used to verify layouts by comparing positions of specific elements.
This may be used to verify layouts by comparing positions of specific elements.
// Using in assertion
_assertEqual([10,20], _position(_image("logo")));
// Fetching and storing value
var $position = _position(_image("logo"));
_log($position[0]); //logs x coordinate (eg. 10)
_log($position[1]); //logs y coordinate (eg. 20)
_positionNative
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.1.0 | 7.5.0 | NA | NA | 10.0.0 |
Available for modes: Browser | Java
_positionNative($el)
Arguments
$el | HTML DOM element | element whose position we need |
Returns
array of integers | An array [x,y] of the elements absolute position in pixels |
Sahi Pro Flowcharts Action :Position Native
Details
This may be used inside native events to find the absolute positions of elements.
This may be used inside native events to find the absolute positions of elements.
// Using in assertion
var $xy = _positionNative(_link("Link Test"));
_assertEqual(222, $xy[1]);
// Fetching and storing value
var $xy = _positionNative(_link("Link Test"));
_log("x coordinate "+ $xy[0] ); //logs x coordinate of the element
_log("y coordinate "+ $xy[1] ); //logs y coordinate of the element
_getSelectionText
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | 7.0.0 | NA | 9.0.0 | NA |
Available for modes: Browser | Windows | Java | SAP
_getSelectionText([$el])
Arguments
$el | HTML DOM element optional | Element in which to look for selection. This is optional only for Browser Automation, as Sahi will automatically look in all frames and elements. |
Returns
string | Text selected by the user (using mouse drag, like we select before copy paste) |
Sahi Pro Flowcharts Action :Get Selection Text
Details
// Using in an assertion
_assertEqual("Search", _getSelectionText());
// Fetching and storing value
var $currentSelectedText = _getSelectionText();
warning
_getSelectionText returns the text that the user has selected on a page.
_getSelectedText returns the text of the selected option in a select dropdown box.
_getSelectedText returns the text of the selected option in a select dropdown box.
_getCopiedText
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
10.0.0 | NA | NA | NA | NA |
Available for modes: Browser
_getCopiedText()
Arguments
None |
Returns
string | Copied text |
Sahi Pro Flowcharts Action :Get Copied Text
Details
Returns the text copied to the system clipboard by a web application.
Returns the text copied to the system clipboard by a web application.
infoJavascript's Clipboard API works only if the browser window is in focus. Additionally, browsers may impose further restrictions on accessing the clipboard. Therefore, it is imperative to use APIs _focusWindow and _clickNative, along with the
_getCopiedText
API, as shown in the example below.infoJavascript's Clipboard API works only if the browser window is in focus. Additionally, browsers may impose further restrictions on accessing the clipboard. Therefore, it is imperative to use Actions Focus Window and Click Native, along with the
Get Copied Text
Action._lockWindow();
_focusWindow();
_clickNative(_button("Copy Text to Clipboard"));
_unlockWindow();
var $copiedText = _getCopiedText();
_assertEqual("Copied text", $copiedText);
Browser Detection APIs
info
Browser detection APIs are used to identify browsers at runtime, so that specific paths in code can be chosen.
_userAgent
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | NA | NA | NA | NA |
Available for modes: Browser
_userAgent()
Arguments
None |
Returns
string | The userAgent string of the current browser |
Sahi Pro Flowcharts Action :User Agent
_getScreenSize
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | NA | NA | NA | NA |
Available for modes: Browser
_getScreenSize()
Arguments
None |
Returns
array of integers | Screen size as an array [x,y]. The first value is the inner width of the browser window and the second value is the inner height |
Sahi Pro Flowcharts Action :Get Screen Size
Details
// Using in an assertion
var $screensize=_getScreenSize();
_assertTrue(($screensize[0]>=783)&&($screensize[0]<=800));
_assertTrue(($screensize[1]>=280)&&($screensize[1]<=400));
info
When dealing with a responsive website, you may want to write a single script to test functionality on different devices along with the desktop.
Some parts of the website UI may be same across different devices but some parts may be different. To test the parts that are different, you would use the _getScreenSize and _userAgent APIs to identify a specific device and write specific code for that device.
Some parts of the website UI may be same across different devices but some parts may be different. To test the parts that are different, you would use the _getScreenSize and _userAgent APIs to identify a specific device and write specific code for that device.
_isIE
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isIE()
Arguments
None |
Returns
boolean | true if the current browser is Internet Explorer, else false |
Sahi Pro Flowcharts Action :Is IE
Details
_isIE9
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5.2 | NA | NA | NA | NA |
Available for modes: Browser
_isIE9()
Arguments
None |
Returns
boolean | true if the current browser is Internet Explorer 9, else false |
Sahi Pro Flowcharts Action :Is IE9
Details
_isIE10
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
4.5.2 | NA | NA | NA | NA |
Available for modes: Browser
_isIE10()
Arguments
None |
Returns
boolean | true if the current browser is Internet Explorer 10, else false |
Sahi Pro Flowcharts Action :Is IE10
Details
_isEdge
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.2.0 | NA | NA | NA | NA |
Available for modes: Browser
_isEdge()
Arguments
None |
Returns
boolean | true if the current browser is Edge, else false |
Sahi Pro Flowcharts Action :Is Edge
Details
_isEdgeNew
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
9.0.0 | NA | NA | NA | NA |
Available for modes: Browser
_isEdgeNew()
Arguments
None |
Returns
boolean | true if the current browser is new Microsoft Edge, else false |
Sahi Pro Flowcharts Action :Is Edge New
Details
_isFF
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isFF()
Arguments
None |
Returns
boolean | true if the current browser is Firefox, else false |
Sahi Pro Flowcharts Action :Is FF
Details
_isFF3
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isFF3()
Arguments
None |
Returns
boolean | true if the current browser is Firefox 3, else false |
Sahi Pro Flowcharts Action :Is FF3
Details
_isFF4
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5.2 | NA | NA | NA | NA |
Available for modes: Browser
_isFF4()
Arguments
None |
Returns
boolean | true if the current browser is Firefox 4, else false |
Sahi Pro Flowcharts Action :Is FF4
Details
_isChrome
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isChrome()
Arguments
None |
Returns
boolean | true if the current browser is Chrome, else false |
Sahi Pro Flowcharts Action :Is Chrome
Details
_isSafari
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isSafari()
Arguments
None |
Returns
boolean | true if the current browser is Safari, else false |
Sahi Pro Flowcharts Action :Is Safari
Details
_isOpera
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isOpera()
Arguments
None |
Returns
boolean | true if the current browser is Opera, else false |
Sahi Pro Flowcharts Action :Is Opera
Details
_isPhantomJS
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | NA | NA | NA | NA |
Available for modes: Browser
_isPhantomJS()
Arguments
None |
Returns
boolean | true if the current browser is PhantomJS, else false |
Sahi Pro Flowcharts Action :Is Phantom JS
Details
_isBrave
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
9.2.1 | NA | NA | NA | NA |
Available for modes: Browser
_isBrave()
Arguments
None |
Returns
boolean | true if the current browser is Brave, else false |
Sahi Pro Flowcharts Action :Is Brave
Details
_isHTMLUnit
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_isHTMLUnit()
Arguments
None |
Returns
boolean | true if the current browser is HTMLUnit, else false |
Sahi Pro Flowcharts Action :Is HTMLUnit
Details
Rich Text Editors (Content Editable elements)
infoRefer to RTE APIs.
Generic attribute fetching mechanism
Most common attributes needed during automation are exposed via Sahi's fetch APIs.However there are lots of DOM attributes which are not exposed.
For example the href attribute of a link is not exposed by any in-built Sahi API.
To work with such attributes, the APIs _fetch, _set and _condition are used.
info
_fetch is a newer API and can be used in place of both _set and _condition.
_fetch
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_fetch($expression)
Arguments
$expression | string|DOM expression | Expression which we wish to evaluate and fetch. |
Returns
string | Value of the expression |
Sahi Pro Flowcharts Action :Fetch
Details
info
_fetch API was introduced later than _set and may be a cleaner way.
For secondary (popup) windows, _fetch can be used only with _selectWindow and not with _popup prefix.
For secondary (popup) windows, _fetch can be used only with _selectWindow and not with _popup prefix.
var $rowCount = _fetch(_table("tableId").rows.length);
// You can also use an expression as a string
var $userAgent = _fetch("navigator.userAgent");
// And fetch results of custom utility functions of your web app
var $value = _fetch("jQuery('#id').val()");
// While working with popup windows use _selectWindow first
_selectWindow("popupWin");
// Fetch table row count from popupWin window
var $rowCount = _fetch(_table("tableId").rows.length);
warning
_fetch is only required for fetching DOM attributes from the browser.
It is NOT required for assigning constants etc.
It is NOT required for assigning constants etc.
$x = _fetch(10) // wrong
_set
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_set($variable, $expression)
Arguments
$variable | variable | Variable into which we wish to get the specific value. |
$expression | DOM Expression | Expression which we wish to evaluate and set. |
Returns
null |
Sahi Pro Flowcharts Action :Set
Details
Sets the value of expression into variable
_set communicates with the browser to evaluate the expression and fetches the result.
Sets the value of expression into variable
_set communicates with the browser to evaluate the expression and fetches the result.
warning
_fetch may be a better way than _set to fetch values from browser.
// Fetching href attribute
var $href = null; // initialize variable
_set($href, _link("Home").href); // set it
// Getting row count of table
var $rowCount = 0; // initialize variable
_set($rowCount, _table("tableId").rows.length); // set it
// Getting column count of table (first row)
var $colCount = 0; // initialize variable
_set($colCount, _table("tableId").rows[0].cells.length); // set it
// Working with popup windows using _popup prefix
var $colCount = 0;
_popup("popupWin")._set($colCount, _table("tableId").rows[0].cells.length); // CORRECT
_set($colCount, _popup("popupWin")._table("tableId").rows[0].cells.length); // WRONG
// Better to use with _selectWindow
var $colCount = 0;
_selectWindow("popupWin"); // Select window first
_set($colCount, _table("tableId").rows[0].cells.length);
warning
_set is only required for fetching DOM attributes from the browser.
It is NOT required for assigning constants etc.
It is NOT required for assigning constants etc.
_set($x, 10) // wrong
_condition
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | NA | NA | NA | NA |
Available for modes: Browser
_condition($expression)
Arguments
$expression | DOM expression | Expression which we wish to evaluate. |
Returns
boolean | true or false based on the expression |
Sahi Pro Flowcharts Action :Condition
Details
if (_condition(_link(0).href == "http://sahi.co.in/")){
_click(_link(0));
}
// Note that this is the same as
var $href = _fetch(_link(0).href);
if ($href == "http://sahi.co.in/"){
_click(_link(0));
}
// or
var $href = null;
_set($href, _link(0).href);
if ($href == "http://sahi.co.in/"){
_click(_link(0));
}
// For popup windows use _selectWindow and then use _condition
_selectWindow("popupWin"); // select Window
// Check condition on popup window
if (_condition(_link(0).href == "http://sahi.co.in/")){
_click(_link(0));
}
warning
_condition is only required for fetching DOM attributes from the browser.
It is NOT required for comparing constants etc. like
$x == 10
Multiple Elements
info
These APIs are used to fetch content from multiple elements.
_collect
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.5.0 | 7.5.0 | NA | NA |
Available for modes: Browser | Windows | Java | Android | iOS
_collect($elementType, $identifier[, $relations])
Arguments
$elementType | string | type of elements to collect. Eg. "_link" , "_button" , "/text/" etc. |
$identifier | string | Sahi Identifier. Can also be just an index. |
$relations | relations optional | Relations like _in, _near etc. |
Returns
array of element stubs | Array of all elements of the specified type matching the identifier within relations |
Sahi Pro Flowcharts Action :Collect
Details
// Collect all textboxes matching any identifier, in table "listing".
// Note the use of match all regular expression "/.*/"
var $textboxes = _collect("_textbox", "/.*/", _in(_table("listing"));
// Iterate and set values on all textboxes
for (var $i=0; $i<$textboxes.length; $i++) {
_setValue($textboxes[$i], "value");
}
_count
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
3.5 | 7.5.0 | 7.5.0 | NA | NA |
Available for modes: Browser | Windows | Java | Android | iOS
_count($elementType, $identifier[, $relations])
Arguments
$elementType | string | type of elements to collect. Eg. "_link" , "_button" , "/text/" etc. |
$identifier | string|object | Sahi Identifier/Attributes JSON. Can also be just an index. |
$relations | relations optional | Relations like _in, _near etc. |
Returns
integer | Count of all elements of the specified type matching the identifier within relations |
Sahi Pro Flowcharts Action :Count
Details
// Count all textboxes matching any identifier, in table "listing".
// Note the use of match all regular expression "/.*/"
var $textboxCount = _count("_textbox", "/.*/", _in(_table("listing")); // may return 5;
// or more explicitly
var $textboxCount = _count("_textbox", {name:"q"});
_collectAttributes
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | 7.5.0 | 7.5.0 | NA | NA |
Available for modes: Browser | Windows | Android | iOS | Java (8.0.0)
_collectAttributes($elementType, $identifier, $attribute[, $relations])
Arguments
$elementType | string | type of elements to collect.
Eg. "_link" , "_button" , "/text/" etc. |
$identifier | string | Sahi Identifier. Can also be just an index. |
$attribute | string|function | attribute or function. |
$relations | relations optional | Relations like _in, _near etc. |
Returns
li_s | Array of element attributes of all elements of the specified type matching the identifier within relations |
Sahi Pro Flowcharts Action :Collect Attributes
Details
Fetching a simple attribute from multiple elements
Fetching one of few simple attributes from multiple elements
Fetching some synthesized/processed values from multiple elements by executing an inline function for each element
Fetching some synthesized/processed values from multiple elements by executing a defined function for each element
Fetching some synthesized/processed values from multiple elements by executing nested functions
Fetching a simple attribute from multiple elements
// Collect the id attribute of all textboxes in table "listing".
// Note the use of match all regular expression "/.*/"
var $textboxIds = _collectAttributes("_textbox", "/.*/", "id", _in(_table("listing")));
// Collect text of divs whose className is menu-item
var $menuTexts = _collectAttributes("_div", "menu-item", "sahiText");
// or more explicitly
var $menuTexts = _collectAttributes("_div", {className:"menu-item"}, "sahiText");
Fetching one of few simple attributes from multiple elements
// Return name or id of textboxes. If name is found return name, else id.
// Note the use of single pipe |.
var $identifiers = _collectAttributes("_textbox", "/.*/", "name|id");
Fetching some synthesized/processed values from multiple elements by executing an inline function for each element
// For each div of className menu-item, function will be called and the current div will be passed as $el.
var $htmls = _collectAttributes("_div", "menu-item", function ($el) {return $el.innerHTML;}, _in(_div("navbar")));
Fetching some synthesized/processed values from multiple elements by executing a defined function for each element
// getInnerHTML will be called for each element whose attribute we are collecting.
function getInnerHTML($el) {
return $el.innerHTML;
}
// For each div of className menu-item, getInnerHTML function will be called and the current div will be passed as $el.
var $htmls = _collectAttributes("_div", "menu-item", getInnerHTML, _in(_div("navbar")));
Fetching some synthesized/processed values from multiple elements by executing nested functions
// Notice the use of browser tag for the second level function called from getHTML.
<browser>
function getInnerHTMLOfParent(el){
return el.parentNode.innerHTML;
}
</browser>
// This is not inside a browser tag.
function getHTML(el) {
// calls another function.
// The called function should be inside a browser tag,
// because of the way Sahi serializes content between proxy and browser.
return getInnerHTMLOfParent(el);
}
var $htmls = _collectAttributes("_div", "menu-item", getHTML, _in(_div("navbar")));
_collectElementsInfo
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.2.1 | 7.5.0 | 7.5.0 | NA | NA |
Available for modes: Browser | Windows | Java (8.0.0)
_collectElementsInfo($elementType[, $relations])
Arguments
$elementType | string | Type of elements to collect. Can be regular expression.
Eg. "_link" , "_button" , "/text/" etc. |
$relations | relations optional | Relations like _in, _near etc. |
Returns
array of objects | Array of Accessor Info object of all elements of the specified type within relations |
Sahi Pro Flowcharts Action :Collect Elements Info
Details
var $accs1 = _collectElementsInfo("/text/"); // Collect all _textbox and _textarea accessor info.
// Collect all _radio accessor infos in div "modes".
var $accs = _collectElementsInfo("_radio", _in(_div("modes")));
/*
$accs = [
{"api":"_radio", "identifiers":{"id":"sahiradio", "index":0, "name":"mode", "value":"on"}, "tag":"INPUT"},
{"api":"_radio", "identifiers":{"id":"javaradio", "index":1, "name":"mode[1]", "value":"on[1]"}, "tag":"INPUT"},
{"api":"_radio", "identifiers":{"id":"rubyradio", "index":2, "name":"mode[2]", "value":"on[2]"}, "tag":"INPUT"}
]
*/
for (var $i=0; $i<$accs.length; $i++) {
var $obj = $accs[$i];
var $identifiers = $obj["identifiers"];
var $el = $obj["api"] + "(\"" + $identifiers["id"] + "\")";
_log($el);
}