无法找到带有XPath表达式的标签的元素
我尝试使用下面的xpath作为标签,但找不到元素无法找到带有XPath表达式的标签的元素,xpath,label,selenium-webdriver,element,locate,Xpath,Label,Selenium Webdriver,Element,Locate,我尝试使用下面的xpath作为标签,但找不到元素 driver.findElement(By.xpath("//div[label[contains(text(),'Patient's Name']]")).isEnabled(); XPath://*[@id='update\u patient\u profile']/div/div[1]/label——取自FirePath 下面是该字段的HTML源代码 <form id="update_patient_profile" action=
driver.findElement(By.xpath("//div[label[contains(text(),'Patient's Name']]")).isEnabled();
XPath://*[@id='update\u patient\u 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吗。您应该使用下面的XPath
//*[@id='update_patient_profile']//div[2]/label[.='Patient's Name']
也可以使用
text()而不是点“。要验证标签文本,也可以使用此路径
//form[@id='update_patient_profile']//div[2]/label[text()='Patient's Name']
//表单[@id='update\u patient\u profile']/label[text()='patient's Name']
由于
标签
标签也是表单标签的子标签。您的HTML源代码已损坏,请检查。看一看关于设置问题格式的说明。