XPath for label after input element?

Viewed 89

I have difficulty coming up with the right XPath for the label element.

<td class="">
    <div class="ui fitted read-only checkbox">
        <input class="hidden" name="id" readonly="" tabindex="0" type="checkbox" value="">
        <label></label>
    </div>
</td>
<td class="">Sara Parker</td>

image

2 Answers

This XPath,

//input[@name="id"]/following-sibling::label

will select all following label sibling elements to input elements with name attributes equal to id.

kjhughes has got the right XPath but if you are open to other locators, a CSS selector is shorter/simpler

input[name="id"] + label

They both will do the same thing but CSS selectors are faster, better supported, and I think easier to read.

Related