Get table row data of only specific class

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
uniadv
Junior Coder
Posts: 29
Joined: Tue Aug 04, 2020 2:16 am

Get table row data of only specific class

Post by uniadv » Tue Oct 06, 2020 6:55 am

Hi,

I usually extract the table row data by counting the number of rows first and then running loop up to the counted rows:

Code: Select all

ChromeFindElements>session_1,xpath,/html/body/div/table/tbody/tr,rows
let>n=0
repeat>n
let>n=n+1
  //......data fetch script.......//
until>n=rows_count
I have come-up with the case where data does not exist in each row of the table, few rows are described as heading with different class name within the table rows:

Table Code:

Code: Select all


<table>
<tbody>
<tr class="table-header">...</tr>
<tr class="data-row">...</tr>
<tr class="data-row">...</tr>
<tr class="data-row">...</tr>
<tr class="heading-row">...</tr>
<tr class="data-row">...</tr>
<tr class="data-row">...</tr>
<tr class="data-row">...</tr>
<tr class="heading-row">...</tr>
<tr class="data-row">...</tr>
<tr class="data-row">...</tr>
</tbody>
</table>

here if i count the number of rows, it gives back the total number of rows including "table-header", "data-row" & "heading-row" which ultimately give the false data on running the loop.

Is there any way to get the data only from particular class, in this case data from "data-row" only?

Regards,
Ushahra

User avatar
Marcus Tettmar
Site Admin
Posts: 7335
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Get table row data of only specific class

Post by Marcus Tettmar » Tue Oct 06, 2020 7:01 am

Yes:

Code: Select all

ChromeFindElements>session_1,xpath,//tr[@class='data-row'],rows
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts