18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
what is difference between _set() and direct assign to a variable
Hi Sahi Team/ User,
what is the difference between using _set() and direct assigning a value to variable
Below is the over all code
Example:
_set($lastPaginationNo, $links[$paginationLen].text); // this is working fine
var $lastPaginationNo = $links[$paginationLen].text; // but this is not working
from the above code, 1st code is working fine where i have used _set() method
when i use directly assinging a value to variable is not working fine
sahi scripts is same as javascript, when this is working fine in javascript then y it is failing in sahi
pls let me know the reason why its not working
thanks in advace
what is the difference between using _set() and direct assigning a value to variable
Below is the over all code
var $pagNoStartFrom = 10
var $links = _collect("_link", "/./", _in(_div("idName")));
var $paginationLen = $links.length;
$paginationLen--;
_set($lastPaginationNo, $links[$paginationLen].text);
if( parseInt($pagNoStartFrom) < parseInt($tempLastPaginationNo) ) {
$paginationLen--;
_set($lastPaginationNo, $links[$paginationLen].text);
}
var $pagNoStartFrom = 10
var $links = _collect("_link", "/./", _in(_div("idName")));
var $paginationLen = $links.length;
$paginationLen--;
var $lastPaginationNo = $links[$paginationLen].text;
if( parseInt($pagNoStartFrom) < parseInt($tempLastPaginationNo) ) {
$paginationLen--;
_set($lastPaginationNo, $links[$paginationLen].text);
}
Example:
_set($lastPaginationNo, $links[$paginationLen].text); // this is working fine
var $lastPaginationNo = $links[$paginationLen].text; // but this is not working
from the above code, 1st code is working fine where i have used _set() method
when i use directly assinging a value to variable is not working fine
sahi scripts is same as javascript, when this is working fine in javascript then y it is failing in sahi
pls let me know the reason why its not working
thanks in advace
Comments
as you might know, Sahi differentiates between browser and proxy context. var $x = 1 would be declaring a proxy variable. $x = _image(1) is just creating a element stub in the proxy. When accessing the image like _image(1).name the browser context is checked for the image. _set is used to bring something from the browser context into the proxy. $x=_image(1).name is stored as is, internaly $x would be "_image(1).name". Whereas _set($x, _image(1).name) really reads the values from the browser context. $x would be "imageName".
As it is kinda confusing when to use _set, rule of thumb is to always use it (or _getText/_getValue or _condition) when you access something on the browser.
Does the make the meaning of set more clear?
Does a _condition() in your if case of the second example work?
Regards
Wormi