dimanche 22 octobre 2017

Select checkbox with EXACT text in label

Hello and thank you for all help in advance. I have been spinning my wheels for hours on this and have combed through several XPath examples but cannot solve my exact problem.

I am trying to find the xPath that would select a checkbox with an EXACT label. However, I cannot use "contains" because there may be several options for the label I am trying to locate.

Here is the html:

  <li> 
    <label class="checkbox"> 
      <input id="role_id_9" name="user[role_ids][]" type="checkbox" value="9"/> Pharmacist with Prescriptive Authority
    </label> 
  </li>  
  <li> 
    <label class="checkbox"> 
      <input id="role_id_10" name="user[role_ids][]" type="checkbox" value="10"/> Pharmacist
    </label> 
  </li>  
  <li> 
    <label class="checkbox"> 
      <input id="role_id_83" name="user[role_ids][]" type="checkbox" value="83"/> Out of State Pharmacist
    </label> 
  </li> 

I am trying to find the checkbox with the label 'Pharmacist'. This xpath would normally work

 //label[contains(., 'Pharmacist')]/input[1]

except that 'Pharmacist with Prescriptive Authority' is listed BEFORE Pharmacist, so because it contains the word 'Pharmacist' it is selected instead. I can not use IDs because my tests are used in multiple environments and the IDs change.




Aucun commentaire:

Enregistrer un commentaire