QA_manager
unread,Jun 11, 2010, 6:13:41 PM6/11/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Selenium Users
I see plenty of questions about XPath, how to write good XPath
expressions, and how to find one element in relation to an easy-to-
find element. For example, with this HTML for a single row in a
table:
<td>
<a href='editBucket.do?subnet=64.0.0.0'>Selenium_Test1</a>
</td>
.
.
.
<td>
<img class="state" src="/images/icn_status_grn.gif">
IN
</td>
<td>
<img class="state" src="/images/icn_status_grn.gif">
IN
</td>
The first node (Selenium_Test1) is easy to find, but the other nodes
are the same (duplicated) in every row of the table, so they can only
be (reliably) found in relation to Selenium_Test1. That is, the table
might look like this:
Selenium_Test1, img, text, img, text
Selenium_Test2, img, text, img, text
Selenium_Test3, img, text, img, text
In order to find the text of the first <td> node that is in the same
row as Selenium_Test2, relative XPath is the only solution I know.
So, are there any tools that allow you to click on two elements and
get a list of possible XPath relational expressions? In this case a
list of relative paths from Selenium_Test1 to the text of the <td>
node might include:
/../following::td[1]
/../following-sibling::td[1]
/../following-sibling::*[img[@class='state']][1]
All three of these work. IMHO, the first is the most fragile; it will
break if another <td> column is inserted between our two targets, or
into their children. The second is not much better, but the third is
fairly robust - it will find the first image with 'class=state' that
follows our parent node, and then find the text from that. Moving the
columns around won't affect it (unless it is moved _after_ the other
image node).
.
I know that XPather says it generates relative XPaths, but I can't get
it to generate anything approaching the examples above. So:
- Is XPather capable of generating a list of relative paths similar
to the one I have outlined here?
- If not, are there other tools that will?
I know that this is a _hard_ problem - trying lots of possible
combinations, figuring out which ones work, and then rank ordering
them in some way - but I know I am not the only one who would like to
have it! :-)
TIA.