How to retrieve attribuut value of a tr based on specific value in a td

186 views
Skip to first unread message

Tonger Core

unread,
Aug 25, 2021, 9:51:01 AM8/25/21
to robotframework-users
Hi all, I have a dynamic table like below. In this example there are two rows but it can also exist out of 10 rows or 20 or 100.

In every row there is a td with policy number. Policey number will always be a unique number in the whole tabel

I want to be able to search for a specific Policynumber and check all the other td values in that specific row.

So for instance if I search on Policynumber 2222222, I want to be able to check that Einddatum = 01-01-2030.

I thought of using the "pl-index" attribuut (1 or 2) in this example and based on that determine the td values of that row. Problem is I do not know how to approach this. 
Can anyone of you guide me in the right direction?

Table:
<table>
<tbody>
<tr data-test-id="202009251816340335219-R1" pl_index="1">
<td data-attribute-name="Einddatum>
<div class="oflowDivM">
<span data-test-id="2016072109335505834280">01-07-2024</span>
</div>
</td>
<td data-attribute-name="Policy number>
<div class="oflowDivM">
<span data-test-id="20200925181804054227467">1111111</span>
</div>
</td>
<td data-attribute-name="Forecast capital>
<div class="oflowDivM">
<span data-test-id="20200925181804054339973">Ja</span>
</div>
</td>
<td data-attribute-name="Kapitaal>
<div class="oflowDivM">
<span data-test-id="202010100021110291fd306869-78a5-474f-9b27-97738364f7fa988">€ 85,23</span>
</div>
</td>
</tr>
<tr data-test-id="202009251816340335219-R2" pl_index="2">
<td data-attribute-name="Einddatum>
<div class="oflowDivM">
<span data-test-id="2016072109335505834280">01-01-2030</span>
</div>
</td>
<td data-attribute-name="Policy number>
<div class="oflowDivM">
<span data-test-id="20200925181804054227467">2222222</span>
</div>
</td>
<td data-attribute-name="Forecast capital>
<div class="oflowDivM">
<span data-test-id="20200925181804054339973">Nee</span>
</div>
</td>
<td data-attribute-name="Kapitaal>
<div class="oflowDivM">
<span data-test-id="202010100021110291fd306869-78a5-474f-9b27-97738364f7fa988">€ 201,56</span>
</div>
</td>
</tr>
<tr data-test-id="202009251816340335219-R3" pl_index="3"></tr>
<tr data-test-id="202009251816340335219-R4" pl_index="4"></tr>
<tr data-test-id="202009251816340335219-R5" pl_index="5"></tr>
<tr data-test-id="202009251816340335219-R6" pl_index="6"></tr>
</tbody>
</table>

Dave Amies

unread,
Aug 26, 2021, 11:17:47 AM8/26/21
to robotframework-users
Hi Tonge,

I hope this helps:

You can use this xpath to get the policy numbers (if you didn't already know them):
//td[@data-attribute-name='Policy number']/span

Once you've collected the policy numbers (or if you already know the policy number you want to target) you can get the Einddatum value that relates to a policy number with this xpath.
//tr//span[text()='2222222']/../../td[@data-attribute-name='Einddatum']/span

You can use robot framework variables in an xpath something like this
${Einddatum}=    Get Text    //tr//span[text()='${PolicyNum}']/../../td[@data-attribute-name='Einddatum']/span

Hopefully that should give you the start you need,

Dave.

Tonger Core

unread,
Aug 27, 2021, 11:13:42 AM8/27/21
to robotframework-users
Hi Dami,

Thanks, that is a nice solution you proposed. I have worked it out and all is working fine.

Thanks for your solution!!

Kind Regards, Tongercore

Op donderdag 26 augustus 2021 om 17:17:47 UTC+2 schreef dami...@gmail.com:
Reply all
Reply to author
Forward
0 new messages