How to get attribute value of a row or column by using xpath of data

213 views
Skip to first unread message

Pragnya Sahoo

unread,
Feb 11, 2015, 1:52:16 AM2/11/15
to seleniu...@googlegroups.com
Hi All,

Below is the HTML structure of an element present in a webtable. Like that there are many other elements in different rows and columns.

<tr id="avlAndFareForm:trainbtwnstns:2" class="rf-dt-r active-row">
<td id="avlAndFareForm:trainbtwnstns:2:j_idt378" class="rf-dt-c">
<a class="trainNoLink" tabindex="2" href="javascript:trainScheFunc('12509')">12509</a>
</td>
</tr>

I will be writing  the xpath for searching that element by using the below, since 12509 will be unique text which I can use to search easily
//a[contains(text(),'12509')]

But now I want to store the attribute value of the "id" (either of row or column) by using the above xpath since the "id" value changes dynamically. So, when I'm running the below script through IDE it is not printing the "id" attribute value

<tr>
<td>storeAttribute</td>
<td>xpath=//a[contains(text(),'12864')]@id</td>
<td>s</td>
</tr>

<tr>
<td>echo</td>
<td>${s}</td>
<td></td>
</tr>

Result:
[info] Executing: |storeAttribute | xpath=//a[contains(text(),'12864')]@id | s |
[info] Executing: |echo | ${s} | |
[info] echo: ${s} [It is not printing the correct value]

Please help me on this.

Er. Debasish Dutta

unread,
Feb 11, 2015, 3:32:16 AM2/11/15
to seleniu...@googlegroups.com
Hi Pragnya,
I think there is some problem in idetifying the element. could you please try with other identifiers. let me know if u need any help.


Thanks
Debasish



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1ce52214-3534-4565-8b55-cb21acb16b9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Thanks & Regards,

Debasish Dutta

Pragnya Sahoo

unread,
Feb 11, 2015, 4:28:57 AM2/11/15
to seleniu...@googlegroups.com
Hi Debasish,

To find my element I need to use the below html line
<a class="trainNoLink" tabindex="2" href="javascript:trainScheFunc('12509')">12509</a>

But i need to get the value of the attribute "id", which is in the line above <a> tag
<td id="avlAndFareForm:trainbtwnstns:2:j_idt378" class="rf-dt-c">

So, don't know how to extract that value through "storeAttribute" command. I have tried lot many ways but can't able to get it.
So, it will be better if you can provide the query to extract that.

Thanks
Pragnya Sahoo

PeterJeffreyGale

unread,
Feb 11, 2015, 5:21:56 AM2/11/15
to seleniu...@googlegroups.com
You can use:

//a[contains(text(),'12509')]/..

to get the parent element of the <a> tag and then use storeAttribute on that element to get  it's ID.

Pragnya Sahoo

unread,
Feb 11, 2015, 5:33:31 AM2/11/15
to seleniu...@googlegroups.com
Thanks Peter.. This works..
Reply all
Reply to author
Forward
0 new messages