Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate element for LABEL with the XPath expression

I am trying the below xpath for Label, but I'm not able to locate the element.

driver.findElement(By.xpath("//div[label[contains(text(),'Patient's Name']]")).isEnabled();

XPath: .//*[@id='update_patient_profile']/div/div[1]/label ---Taken from FirePath.

Below is the HTML source for the field.

<form id="update_patient_profile" action="/subscriber/" method="post" name="update_patient_profile"> 
  <div class="subscriberAddPatient"> 
    <div class="formData nameInputs"> 
  <label for="first_name">Patient's Name</label>
  <input id="first_name" class="left nameRule" type="text" onblur="resetTxtAdd($(this))" onfocus="emptyFieldAdd($(this))" onclick="emptyFieldAdd($(this))" name="first_name" value="First Name" maxlength="24"/>

Can anyone suggest me the correct XPath for the Label.

like image 212
pratik Avatar asked Sep 24 '13 17:09

pratik


1 Answers

You should use the below XPATH

 //*[@id='update_patient_profile']//div[2]/label[.='Patient's Name']
like image 159
Arup Rakshit Avatar answered Sep 28 '22 17:09

Arup Rakshit