18 January 2026:


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.

Accessing Child Elements

haripriya.yerraharipriya.yerra Members
edited November -1 in Sahi - Open Source
Hi,

i have a html like below

<div id="menu">
<ul>
<li id="open" enabled="false">
<a href="#">Open...</a>
</li>
</ul>
</div>

<div id="menu1">
<ul>
<li id="open" enabled="false">
<a href="#">Open...</a>
</li>
</ul>
</div>

now i want know the list item open is enabled or not in 'Menu div' ( Not in Menu1 div )

i can check like this if it is only one unique id _listItem("novadrive-mnu-accesssettings").getAttribute("enabled")

but its not, so i need to check with related parent element, so is there any option to get like below

_alert(_div("menu").listItem("Open").getAttribute("enabled"));

please help me.

Thanks and Regards,
Priya.

Comments

  • narayannarayan Administrators
    Have a look at DOM relations _in and _near described here: http://sahi.co.in/w/browser-accessor-apis

    In your case, use:

    _alert(_listItem("Open", _in(_div("menu"))).getAttribute("enabled"));

    Regards,
    Narayan
  • Thanks for the response, its working fine when that enabled attribute binds to the tag before loading only, if i am trying to bind dynamically to the tag its returning null value for the enabled attribute.


    example:

    <li id='open' enabled='true'>open</li> -> here working fine


    <li id='open'>open</li>
    $('#open').attr('enabled', 'true');

    in this case its not working.
  • narayannarayan Administrators
    You code seems to be working fine for me on IE and FF.

    Btw, it is better to assert properties which are visible to the user. Checking for a property which is code specific may not be a real functional test.
  • thanks for the response, its working fine.
This discussion has been closed.