<document>
<html class=" js " lang="en" style="" xmlns="http://www.w3.org/1999/xhtml">
<head id="head">
<body class="modern operational">
<div class="row btm16">
<div class="col-xs-30">
<label>Adjust To </label>
</div>
<span id="pb33352:eastFieldForm:j_idt2056:adjInputTextPanel">
<input id="pb33352:eastFieldForm:j_idt2056:newValueNumber" class="form-control" type="text" maxlength="11" name="pb33352:eastFieldForm:j_idt2056:newValueNumber"/>
<span>
<span id="pb33352:eastFieldForm:j_idt2056:adjustToUnit"/>
</span>
</span>
<div class="col-md-40"/>
<span id="pb33352:eastFieldForm:j_idt2056:errorMessages"/>
</div>
</body>
</html>
</document>
我有一个上面的简单页面,其中有一个标签和一个文本框。我想在文本框中输入文本。
对我有帮助的 XPATH
是 //*[contains(text(),normalize-space('Adjust To'))]//..//..//*[self::input]
.
对于上述解决方案,我不满意在中间使用多个 //..
。
有没有更好的方法来获取此XPATH
。
请注意,我需要通过查找文本“调整到”来找到 xpath
最佳答案
我会使用following
axis :
//label[normalize-space(.) = 'Adjust To']/following::input
或者,我认为使用 id
的“adjInputTextPanel”部分也是一个足够好的定位器:
//span[contains(@id, 'adjInputTextPanel')]/input
关于xml - Xpath 改进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38397703/