【发布时间】:2016-03-14 04:06:38
【问题描述】:
我有多个 HTML <input> 元素,如下所示:
<input type="text" class="information">
<input type="text" class="information">
<input type="text" class="information">
在这些输入元素中输入不同的文本(例如“hello”“hi”“hey”)并保存后,我可以使用element.getAttribute("value") 打印出它们的值,即“hello”“hi”“hey” .
但是,当我尝试使用 XPath 抓取这个输入元素时
//input[@class='information' and @value='hello']
//input[@class='information' and @value='hi']
//input[@class='information' and @value='hey']
它不起作用(无法用表达式识别元素)。知道为什么会发生这种情况,或者在这种情况下如何使用 XPath 获取输入元素吗?提前致谢!
【问题讨论】:
-
您应该能够在 xpath 中没有 value 属性的情况下继续,即使用
//input[@class='information'] -
对不起,我忘了提,我的 html 中有多个输入看起来完全一样,我正在尝试根据需要单独输入。
-
您想编辑问题并添加 html 吗?
-
我编辑了描述,希望它现在更有意义?谢谢
-
你期望的输出是什么?