Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Xpath help!

Question posted by: hurstbp (Newbie) on June 27th, 2008 03:55 PM
Hello,

I want to use xpath to reference a link in a table cell based on the location of a cell containing a related string two columns to the right along the same row. To clarify:

<table>
<tbody>
<tr>
<td><a href="link">link</a></td> <-- I want to point to a[1] in this cell
<td> </td>
<td>string</td> by referencing this string's td predicate -2
</tr>
</tbody>
</table>

This is my xpath expression so far. It obviously doesn't work:

//td[contains(text(), 'string')-2]/a[1]

I'm writing test scripts in Canoo's WebTest. Basically, I need to run through a table of data and find an ID number for a specific case, then follow the link for that case's details page, which is located in a different cell along the same row. Xpath works in other test scripts I've written, finding links that exist always in the same location, but may have different urls driving them. Thank you for your help.
jkmyoung's Avatar
jkmyoung
Moderator
793 Posts
June 27th, 2008
05:27 PM
#2

Re: Xpath help!
Not exactly sure what you mean, but it could be:
//td[contains(text(), 'string')]/preceding-sibling::td[2]/a[1]

Usage of preceding-sibling:: axis to make this work.

Reply
hurstbp's Avatar
hurstbp
Newbie
3 Posts
June 27th, 2008
06:07 PM
#3

Re: Xpath help!
That did it!! Thank you!

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,170 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top XML Forum Contributors