Sara
Sara

Reputation: 23

XPath for label after input element?

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

Upvotes: 2

Views: 334

Answers (2)

JeffC
JeffC

Reputation: 25746

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.

Upvotes: 1

kjhughes
kjhughes

Reputation: 111726

This XPath,

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

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

Upvotes: 1

Related Questions