I've tried the following xpath but none of them work. The id is listed differently everytime. Next to the checkbox is this word " poetin alfa"

- //input[@type='checkbox'][@value='on']
- //*[@id='id1']
-//input[contains(text(),'<poetin alfa>')]/preceding-sibling::input[@type='checkbox']
- //input[contains(text(),'<poetin alfa>')]/following-sibling::input[@type='checkbox']

<span class="v-checkbox v-widget">
<input id="id1" type="checkbox" value="on" tabindex="0"/>
<label for="id1"/>
  • 2
    Where is that word in your example html?
    – Alexey R.
    Jul 3, 2018 at 22:31
  • <poetin alfa> are an other checkbox value ? Another tag with "poaetin alpha" as text ? In your XPath example, you seem to be looking for a tag into a text of another tag. Please provide full example of your HTML which containing the poetin alfa tag, it will be easier to help you
    – Marsso
    Jul 4, 2018 at 5:12
  • Please provide more info Jul 4, 2018 at 5:16
  • Are your <span>, <input> and <label> all nested one inside the other? Please show more of your HTML.
    – Mate Mrše
    Jul 4, 2018 at 10:17
  • The id alone should work since it's supposed to be unique, but I suspect that the HTML code you think is shown is not what is actually shown. You're searching for text in a label that does not appear to be in the label tag. I would think a proper label would be <label for="id1">poetin alfa</label> or if it really does have ankle brackets <label for="id1">&lt;poetin alfa&gt;</label> Jul 5, 2018 at 13:08

1 Answer 1


Try with the below xpath.

//input[contains(text(),'poetin alfa')]/preceding-sibling::input[@type='checkbox']

As you didnt provide the html structure of the text (poetin alfa), I will go with your xpath. The xpath which you constructed has <>.


You should remove the <> in contains text().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.