'XPath, how to select a "checkbox" that is a child to an element with a custom content

I have a task that requires using some XPath, the site is http://todolistme.net/

So, I need to select a checkbox: //input[contains(@type, 'checkbox')]

But before that, I need to add a custom item by typing it into the field and pressing enter, so it appears in a list of "todos". i.e. let's enter "customToDo".

So now I need to select the only one checkbox //input[contains(@type, 'checkbox')] which is a child of an //ul[contains(@id, 'mytodos')] and contains my custom list item //span[contains(text(), 'customToDo')].

How can I do that?



Solution 1:[1]

Get locator of li that contains text - and select it's input:

 //li[./span[contains(text(), 'customToDo')]]/input

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vitaliy Moskalyuk