【问题标题】:Can't locate some text using xpath from certain elements无法使用来自某些元素的 xpath 定位某些文本
【发布时间】:2017-06-18 20:21:17
【问题描述】:

是否可以使用 xpath 从以下元素中找到“值”属性中的名称:

<div class="div_input_place">
    <input name="txt_name" type="text" value="ANWESH SHETTY" maxlength="20" id="txt_name" disabled="disabled" tabindex="2" class="aspNetDisabled textboxDefault_de_active_student">
</div>

我尝试了以下表达式,但没有找到结果:

//input[@value]/text()

【问题讨论】:

  • //input/@value

标签: xpath


【解决方案1】:

//input[@value]/text() 将定位一个具有value 属性的input 元素,然后它会为您提供该元素的“文本”——它是空的。

您需要找到input 元素,例如,通过id,然后获取value 属性的值:

//input[@id = "txt_name"]/@value

【讨论】:

猜你喜欢
  • 2019-11-14
  • 1970-01-01
  • 1970-01-01
  • 2020-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多