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.

Need help finding element

pampam Members
edited November -1 in Sahi - Open Source
<table>
<tr>
<td>
<a id="someLink_3">
C
</a>
</td>
</tr>
</table>
<table>
<tr>
<td id="someId_1">
<input type=checkbox />
<a id="someLink_1">
B
</a>
</td>
</tr>
<tr>
<td id="someId_2">
<input type=checkbox />
<a id="someLink_2">
B
</a>
</td>
</tr>
<tr>
<td id="someId_3">
<input type=checkbox />
<a id="someLink_3">
C
</a>
</td>
</tr>
</table>



I need to check the check box near link "somelink_3". But i dont want to hardcode the link id since it can change. I am using the following code to find it. But it does not work. I do not want to use indexs like C[1] since the postions can change.

Note: Link"C" in the first table is optional and my code works when it is missing. It does not work when the link is present and i get error :TypeError: 'checked' is null or not an object
No trace available"


_check(_checkbox(0, _parentNode(_link("/someLink_/")), _near(_link("C"))));

Comments

  • Hi pam,

    You can use this:

    _check(_checkbox(0, _near(_link("C", _in(_table(1))))));

    Let me know if you face any problem.

    Regards
    Sumitra
  • pampam Members
    Thank you for the response but we cannot use table index since there are multiple tables and the positions of the tables could change. Basically we have to filter by link text (“C”) for a link element which we find by ID (which is also dynamic and it needs to be referred by regular expression)
    When we filter by link element ID using a regular expression we probably get an array of elements since we have many links with similar IDs but different numbers at the end:
    someLink_3
    someLink_4
    someLink_100
    Now, we have to filter this array for any links who’s text is “C”.
  • Hi pam,

    According to the html code you have given, the id's for "C" are same so you cant develop a relation like you have specified.

    You can fix the id issue or check your table if you can establish a relation with the element and use the appropriate code.

    Regards
    Sumitra
Sign In or Register to comment.