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

标签 xpath label selenium-webdriver element locate

我正在尝试使用下面的标签 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']

关于xpath - 无法使用 XPath 表达式定位 LABEL 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18988157/

相关文章:

python - 无法在 python 中使用 XPATH 获取文本值

python - lxml XPath - 如何从节点获取连接文本

label - 瓦丁 : My label ignores the carriage return character

C# Labels TextAlign 在 OnPaint 覆盖后不起作用

javascript - 是否可以使用 JSCover 或任何其他工具来获取在浏览器中运行 Java Selenium WebDriver 测试的 JavaScript 代码覆盖率?

使用 xpath 解析包含默认命名空间的子节点的 XML

java - 使用 Selenium Webdriver 找不到特定标签

java - LibGDX 标签不绘图

java - Selenium - Java - 无法单击链接

java - 如何在 Selenium WebDriver 中使用日期选择器选择特定日期