wuputah
wuputah

Reputation: 11395

XPath to find table row based on containing field with associated label and value

Here's what I have right now:

//tr[.//*[@id = string(../label[.='foo']/@for) and @value='bar']]

I know this works:

//tr[.//label[.='foo']/@for]

I also confirmed that the string() function works as expected, but it seems to be hung up on matching the string() against the id attribute. Any idea why?

Here's a bit of X[HT]ML that should match this - it should find the second row:

<tr>
  <td>
     <label for="thing1">foo</label>
     <input id="thing1" value="not-bar" />
  </td>
</tr>
<tr>
  <td>
     <label for="thing2">foo</label>
     <input id="thing2" value="bar" />
  </td>
</tr>

Thanks!

Upvotes: 0

Views: 1543

Answers (1)

Flack
Flack

Reputation: 5892

//tr[*/input
    [@id = ../label[.='foo']/@for and @value='bar']
    ]

Looks sufficient.

Upvotes: 2

Related Questions