xpath - how to find the second checkbox?
xml, xpath
Solution
Use `()`:
(//li[contains(@id,'topic_roles_input')]//input[@type="checkbox"])[2]
Honestly your 1st as well as 2nd XPath select both checkboxes.
Problem
Given this HTML ``` <ol> <li id="topic_roles_input"> <fieldset class="choices"> <input id="topic_roles_none" name="topic[role_ids][]" type="hidden" value="" /> <ol class="choices-group"> <li class="choice"> <label for="topic_role_ids_107"> <input id="topic_role_ids_107" name="topic[role_ids][]" type="checkbox" value="107" />Language Therapist </label> </li> <li class="choice"> <label for="topic_role_ids_106"> <input id="topic_role_ids_106" name="topic[role_ids][]" type="checkbox" value="106" />Speech Therapist </label> </li> </ol> </fieldset> </li> </ol> ``` I can select the first checkbox with: ``` xpath=(//li[contains(@id,'topic_roles_input')]//input[@type="checkbox"][1]) ``` But I can't select the second with: ``` xpath=(//li[contains(@id,'topic_roles_input')]//input[@type="checkbox"][2]) ``` How can I select the second checkbox, avoiding using the 106 / 107 id's (this is being used for repeated tests).