Use Xpath to get all the rows of a table after a specific row in Automation Anywhere

1.9k views Asked by At

I am trying to get the values of all the row after a specific row(This specific row can be identified using id) using xpath. Kindly note that i am using it in automation anywhere's object cloning command to locate and fetch the details. lets say this is the table:

<table class="actiontable" >
<tbody>
<tr></tr>
<tr></tr>
<tr id="h32423">
<td class="claim"><span id="claimants">Claimants</span></td>
</tr>
<tr id="a23">
<td id="g543"><a href="some site">Edward Hunter</a> </td>
</tr>
<tr>
<td id="g544"><a href="some site">Jane Doe</a> </td>
</tr>
<tr></tr>
</tbody>
</table>

Here in the above table I need to fetch all the name after the Claimants row. Any suggestions?

3

There are 3 answers

0
Amrendra Kumar On

You need to check the preceding-sibling data like this:

//tr[preceding-sibling::tr[normalize-space(.)='Claimants']]

You can try this as per your comment:

/table[@class='actiontable']/descendant::tr[normalize-space(lower-case(.))!= 'claimants']
2
Dohsan On

For your simple example you can do the following in the Automation Anywhere editor:

Add a loop command with a Times condition of 2

Inside the loop object clone one of the fields you want to access and change the DOMXPath to

/html/body/table[1]/tbody[1]/tr[$Counter$+3]/td[1]/a[1]

Select Action to be Get Property and Select Property to HTML InnerText Assign this to a variable of your choice

Output this variable via a message box command

When run you should then see displayed the two names.

In this we are using the AA counter variable to iterate through the DOMXPath. I have adjusted it by 3 as there are 3 <tr> tags before the row you wish to start on

0
Pandarian Ld On

I'm not sure whether it's too late to answer or not. I think the following XPath match your condition.

//tr[td[span[@id='claimants']]]/following-sibling::tr/td/a

*You can change /tr/td/a to /tr or /tr/td according to which element you want to access

I try this XPath in XPath Search console on Google Chrome and it navigate to all a tags after the row which has ID = claimants.

As I'm quite new to AA, I don't know how to loop through those a tags getting from the XPath. But I hope this help you solve the problem. :)

[Update] I found the solution
1. Using //tr[td[span[@id='claimants']]] with Object Cloning to get the index of the specific row. Let's say the index value is stored in variable $vIndex$
2. Loop through all td in the table
3. If the $Counter$ > $vIndex$ THEN that is the row under the specific row.