无法使用 XPath 表达式定位 LABEL 的元素

2023-12-29

我正在尝试使用下面的 xpath 作为标签,但我无法找到该元素。

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。


你应该使用下面的XPATH

 //*[@id='update_patient_profile']//div[2]/label[.='Patient's Name']
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 XPath 表达式定位 LABEL 的元素 的相关文章

随机推荐