我正在尝试使用以下xpath作为Label,但我无法找到该元素。
driver.findElement(By.xpath("//div[label[contains(text(),'Patient's Name']]")).isEnabled();
XPath:.//*[@id='update_patient_profile']/div/div[1]/label
---取自FirePath。
以下是该字段的HTML源代码。
<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"/>
任何人都可以向我推荐标签的正确XPath。
答案 0 :(得分:6)
您应该使用以下 XPATH
//*[@id='update_patient_profile']//div[2]/label[.='Patient's Name']
答案 1 :(得分:1)
//form[@id='update_patient_profile']/label[text()='Patient's Name']
由于label
标记也是表单标记的子标识。
答案 2 :(得分:0)
也可以使用 text()而非点“。”。要验证标签文本,也可以使用此路径
//form[@id='update_patient_profile']//div[2]/label[text()='Patient's Name']