[英]How to uniquely identify xpath for multiple tags and multiple values
我有以下HTML:
<div class=‘content active’>
<div>
<div class=‘var’>
<div class=‘field var-field’>
<label>Interface Name</label>
<div class=‘ui input’>
<input type=‘input’ placeholder=‘.*’ value> ==$0
</div>
</div>
</div>
</div>
<div>
<div class=‘var’>
<div class=‘field var-field’>
<label>Neighbor Id</label>
<div class=‘ui input’>
<input type=‘input’ placeholder=‘.*’ value> ==$0
</div>
</div>
</div>
</div>
</div>
我需要将文本发送到带有标签的文本框:接口名称。 有没有一种方法可以唯一地编写xpath,以将文本发送到文本框 。 请注意,唯一标识唯一方法是使用标签。 标记中的其他字段都相同。 我尝试使用AND运算符。 没运气。 请帮我在这里。
尝试这个 :
//label[text()='Interface Name']/following-sibling::div/child::input
要将文本相对于<label>
标签发送到<input>
元素,可以创建如下函数:
def test_me(myText):
driver.find_element_by_xpath("//label[.='" + myText + "']//following::div[1]/input").send_keys("hello")
现在,您可以在脚本中的任何位置调用此函数,如下所示:
test_me("Interface Name")
# or
test_me("Neighbor Id")
您可以使用此XPATH:- //*[text()='Interface Name']/following-sibling::div/input"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.