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.
Handling Dynamic Element IDs with Sahi
We have recently started using Sahi OS version for automation. We have installed Sahi OS on Windows XP and testing on IE8 browser. The version of Sahi used is 3.5(Build 2011-07-19).
We are consistently facing problem using the "near" API to handle Dynamic IDs. We are trying to click on a checkbox with name "userRoleID" beside a value "Role1331561773295". Please note that there are several checkbox's on the same page with the same name, but having different values beside the checkbox. We have tried various options listed below. But none seem to work.
_click(_checkbox("/userRoleID/[2]",_near(_parentRow(_cell("Role1331561773295")))));
_click(document.forms.elements,_near(_cell("Role1331561773295")));
_click(_checkbox("/userRoleID/[2]",_near(_div("Role1331561773295"))));
_click(_checkbox("/userRoleID/",_near(_cell("Role1331561773295"))));
_click(_checkbox(/userRoleID/,_near(_cell("Role1331561773295"))));
_click(_checkbox(userRoleID,_near(_cell("Role1331561773295"))));
_click(_checkbox("userRoleID",_near(_cell("Role1331561773295"))));
_click(_checkbox("userRoleID/",_near(_cell("Role1331561773295"))));
_click(_checkbox("on",_near(_cell("Role1331561773295"))));
_click("_checkbox","/./",_near(_cell("Role1331561773295")));
_click("_checkbox",_near(_cell("Role1331561773295")));
_click(input.checkbox,_near(_cell("Role1331561773295")));
_click(input.checkbox,_near(_cell("Role1331561773295")));
_click("input.checkbox",_near(_cell("Role1331561773295")));
_highlight(_checkbox("userRoleID",near(_cell("Role1331561773295")),_under(_cell("Check if this user can be used for web service requests"))));
_mouseOver(_checkbox("userRoleID",near(_cell(_table("displayTable"),"Role1331561773295",2))));
_click(_checkbox("userRoleID",near(_cell(_table("displayTable"),"Role1331561773295",2))));
_click(_checkbox("userRoleID",near(_cell("Role1331561773295"))));
The properties of the checkbox as displayed in Sahi controller is listed below.
nextSibling={{[object Text]}};
nextSibling=[object Text];
childNodes={{[object NodeList]}};
childNodes=[object NodeList];
previousSibling={{[object HTMLBRElement]}};
previousSibling=[object HTMLBRElement];
nodeName=INPUT;
currentStyle={{[object CSSCurrentStyleDeclaration]}};
currentStyle=[object CSSCurrentStyleDeclaration];
clientHeight=13;
style={{[object CSSStyleDeclaration]}};
style=[object CSSStyleDeclaration];
nodeType=1;
scopeName=HTML;
offsetWidth=19;
filters={{[object]}};
filters=[object];
scrollHeight=13;
offsetTop=156;
parentNode=[object HTMLTableCellElement];
tagName=INPUT;
className=checkbox;
behaviorUrns={{[object BehaviorUrnsCollection]}};
behaviorUrns=[object BehaviorUrnsCollection];
parentTextEdit={{[object HTMLBodyElement]}};
parentTextEdit=[object HTMLBodyElement];
ownerDocument={{[object HTMLDocument]}};
ownerDocument=[object HTMLDocument];
offsetParent=[object HTMLTableCellElement];
parentElement=[object HTMLTableCellElement];
children={{[object HTMLCollection]}};
children=[object HTMLCollection];
readyState=complete;
contentEditable=inherit;
document={{[object HTMLDocument]}};
document=[object HTMLDocument];
sourceIndex=267;
runtimeStyle={{[object CSSStyleDeclaration]}};
runtimeStyle=[object CSSStyleDeclaration];
scrollWidth=13;
attributes={{[object NamedNodeMap]}};
attributes=[object NamedNodeMap];
offsetHeight=19;
clientWidth=13;
outerHTML=<INPUT class=checkbox onclick=checkboxClicked(this) value=5985 type=checkbox name=userRoleID hasAttached="true" jQuery1331806774828="109">;
all={{[object HTMLCollection]}};
all=[object HTMLCollection];
offsetLeft=4;
value=5985;
status=true;
maxLength=2147483647;
loop=1;
form={{[object HTMLFormElement]}};
form=[object HTMLFormElement];
start=fileopen;
size=20;
checked=true;
type=checkbox;
name=userRoleID;
hasAttached=true;
jQuery1331806774828=109;
Could some one let me know what could be problem?
We are consistently facing problem using the "near" API to handle Dynamic IDs. We are trying to click on a checkbox with name "userRoleID" beside a value "Role1331561773295". Please note that there are several checkbox's on the same page with the same name, but having different values beside the checkbox. We have tried various options listed below. But none seem to work.
_click(_checkbox("/userRoleID/[2]",_near(_parentRow(_cell("Role1331561773295")))));
_click(document.forms.elements,_near(_cell("Role1331561773295")));
_click(_checkbox("/userRoleID/[2]",_near(_div("Role1331561773295"))));
_click(_checkbox("/userRoleID/",_near(_cell("Role1331561773295"))));
_click(_checkbox(/userRoleID/,_near(_cell("Role1331561773295"))));
_click(_checkbox(userRoleID,_near(_cell("Role1331561773295"))));
_click(_checkbox("userRoleID",_near(_cell("Role1331561773295"))));
_click(_checkbox("userRoleID/",_near(_cell("Role1331561773295"))));
_click(_checkbox("on",_near(_cell("Role1331561773295"))));
_click("_checkbox","/./",_near(_cell("Role1331561773295")));
_click("_checkbox",_near(_cell("Role1331561773295")));
_click(input.checkbox,_near(_cell("Role1331561773295")));
_click(input.checkbox,_near(_cell("Role1331561773295")));
_click("input.checkbox",_near(_cell("Role1331561773295")));
_highlight(_checkbox("userRoleID",near(_cell("Role1331561773295")),_under(_cell("Check if this user can be used for web service requests"))));
_mouseOver(_checkbox("userRoleID",near(_cell(_table("displayTable"),"Role1331561773295",2))));
_click(_checkbox("userRoleID",near(_cell(_table("displayTable"),"Role1331561773295",2))));
_click(_checkbox("userRoleID",near(_cell("Role1331561773295"))));
The properties of the checkbox as displayed in Sahi controller is listed below.
nextSibling={{[object Text]}};
nextSibling=[object Text];
childNodes={{[object NodeList]}};
childNodes=[object NodeList];
previousSibling={{[object HTMLBRElement]}};
previousSibling=[object HTMLBRElement];
nodeName=INPUT;
currentStyle={{[object CSSCurrentStyleDeclaration]}};
currentStyle=[object CSSCurrentStyleDeclaration];
clientHeight=13;
style={{[object CSSStyleDeclaration]}};
style=[object CSSStyleDeclaration];
nodeType=1;
scopeName=HTML;
offsetWidth=19;
filters={{[object]}};
filters=[object];
scrollHeight=13;
offsetTop=156;
parentNode=[object HTMLTableCellElement];
tagName=INPUT;
className=checkbox;
behaviorUrns={{[object BehaviorUrnsCollection]}};
behaviorUrns=[object BehaviorUrnsCollection];
parentTextEdit={{[object HTMLBodyElement]}};
parentTextEdit=[object HTMLBodyElement];
ownerDocument={{[object HTMLDocument]}};
ownerDocument=[object HTMLDocument];
offsetParent=[object HTMLTableCellElement];
parentElement=[object HTMLTableCellElement];
children={{[object HTMLCollection]}};
children=[object HTMLCollection];
readyState=complete;
contentEditable=inherit;
document={{[object HTMLDocument]}};
document=[object HTMLDocument];
sourceIndex=267;
runtimeStyle={{[object CSSStyleDeclaration]}};
runtimeStyle=[object CSSStyleDeclaration];
scrollWidth=13;
attributes={{[object NamedNodeMap]}};
attributes=[object NamedNodeMap];
offsetHeight=19;
clientWidth=13;
outerHTML=<INPUT class=checkbox onclick=checkboxClicked(this) value=5985 type=checkbox name=userRoleID hasAttached="true" jQuery1331806774828="109">;
all={{[object HTMLCollection]}};
all=[object HTMLCollection];
offsetLeft=4;
value=5985;
status=true;
maxLength=2147483647;
loop=1;
form={{[object HTMLFormElement]}};
form=[object HTMLFormElement];
start=fileopen;
size=20;
checked=true;
type=checkbox;
name=userRoleID;
hasAttached=true;
jQuery1331806774828=109;
Could some one let me know what could be problem?
Comments
_check(_checkbox(0,_near(_cell("Role1331561773295"))));
Hope, that might help you.
<tr>
<td class="emsLabel">Roles:</td>
<td>
<input class="checkbox" type="checkbox" onclick="checkboxClicked(this)" value="5977" name="userRoleID">
Create RT Role
<br>
<input class="checkbox" type="checkbox" onclick="checkboxClicked(this)" value="5978" name="userRoleID">
Create ST Reason role
<br>
<input class="checkbox" type="checkbox" onclick="checkboxClicked(this)" value="5979" name="userRoleID">
CreateUserAccounts
<br>
<input class="checkbox" type="checkbox" onclick="checkboxClicked(this)" value="5981" name="userRoleID">