4

I'm using Selenium IDE 1.7.1 to select the checkbox that corresponds with invoice # 405357. Css seems to allow me to move forward in selecting an element, but not backward. So this would select the $420:

css=td:contains('405357') + td

Any ideas for a workaround in order to select a the checkbox? Ideally the workaround wouldn't involve going backward or forward but would just say select checkbox

css=input#paymentsForm_invoiceToPayIds if td:contains('405357')

I'd prefer it to be in CSS, but XPath would be ok too.

Thank you!

enter image description here

<table>
<tbody>
<tr>
<td>
<input id="paymentsForm_invoiceToPayIds" type="checkbox" onclick="calculateInvoices(this)" value="405357" name="invoiceToPayIds">
<input id="__checkbox_paymentsForm_invoiceToPayIds" type="hidden" value="405357" name="__checkbox_invoiceToPayIds">
</td>
<td>405357</td>
</tr>
</tbody>
</table>
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
HRVHackers
  • 2,793
  • 4
  • 36
  • 38
  • Be careful - while you can have multiple checkboxes of the same name in order to group them, they must each have their own unique ID. Just sticking the invoice ID at the end of each checkbox ID should do the trick. – BoltClock Mar 17 '12 at 05:19

3 Answers3

5

I believe :contains() works for the parent tr too. Try this:

css=tr:contains('405357') input[type="checkbox"]
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Sweeet - precisely what I was looking for. This will work even if the invoice id# isn't in the checkbox attributes. – HRVHackers Mar 17 '12 at 15:48
2

You can't do this in real CSS, because real CSS doesn't have :contains. But in XPath, it's simple: //tr[//input[@value="405357"]]//input[@type="checkbox"], which means "The checkbox contained in the table row that contains an input field with the value '405357'".

Ross Patterson
  • 9,527
  • 33
  • 48
  • Actually, [CSS *used* to have `:contains()`](http://stackoverflow.com/questions/4781141/why-h3nth-child1containsa-selector-doesnt-work/4781167#4781167), then it got dropped, but Selenium implements it anyway. – BoltClock Mar 17 '12 at 16:44
  • `:contains()` was only a proposal, and it got dropped between 7 and 11 years ago, long before [CSS3 Selectors](http://www.w3.org/TR/2011/REC-css3-selectors-20110929) was published. People need to get over that, it ain't never comin' back :-) – Ross Patterson Mar 17 '12 at 23:24
  • Selenium doesn't implement `:contains()`. But depending on the browser you're using, the browser may, or Selenium may fall back to using [Sizzle](http://en.wikipedia.org/wiki/Sizzle_(selector_engine)), which does. So it's an iffy proposition, and should be avoided. – Ross Patterson Mar 17 '12 at 23:27
  • Huh, I was under the impression that Selenium used its own selector engine all along :/ – BoltClock Mar 18 '12 at 08:11
0
//input[@type='checkbox' and @value="405357"]

try out this one

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Rohit Ware
  • 1,982
  • 1
  • 13
  • 29