Retrieving Values of Custom Elements using Watir

Farooq Yousuf
FusionQA
Published in
Jan 25, 2022

Let’s say your application has a table and rows, something like this:

<tr data-report-id=’11149' class>…</tr><tr data-report-id=’11147' class>‘info’</tr>

We want to retrive the value of the custom element ‘data-report-id’ for the second row or tr (table row). This can be done by using the method ‘attribute_value’ with the following code:

Note: browser is a previously instantiated Watir browser.

browser.trs[1].attribute_value(‘data-report-id’)

That will yield ‘11149’

--

--