tags:

views:

325

answers:

1

I find that sometimes, the value = "" is missing. So I am reverting to querying for the normalized inner Text.

<label><input type="radio" name="addThree">A Radio</label>

<label><input type="checkbox" name="hasPic">   A Checkbox  </label>

Here are the xpath's respectively...Are these correct?

//label/input[normalize-space(text()) = "A Radio"]
//label/input[normalize-space(text()) = "A Checkbox"]
+1  A: 

It should work in this case, but it is not the best way; better omit the parameter to normalize-space (which then makes it equivalent to . which is the concatenation of all text content of the input element). Using it the way you did may cause problems if there are multiple text nodes inside the input element, which may happen if you also have comments or processing instructions inside.

Martin v. Löwis