Selenium 如何根据同级输入的@id选择span
我有下面的标签,这是一个用于多个选择选项按钮的标签,每个选择都有其on div,其中有一个标签,然后在该标签中有一个ID,我需要使用该ID来确定要单击哪个选项Selenium 如何根据同级输入的@id选择span,selenium,testing,xpath,Selenium,Testing,Xpath,我有下面的标签,这是一个用于多个选择选项按钮的标签,每个选择都有其on div,其中有一个标签,然后在该标签中有一个ID,我需要使用该ID来确定要单击哪个选项 <label class="custom-toggle-checkbox-label"> <input type="checkbox" class="custom-toggle-checkbox-input" id="selectOption_1
<label class="custom-toggle-checkbox-label">
<input type="checkbox" class="custom-toggle-checkbox-input" id="selectOption_1_Value"
value="false">
<span class="custom-toggle-checkbox-slider"></span>
</label>
<label class="custom-toggle-checkbox-label">
<input type="checkbox" class="custom-toggle-checkbox-input" id="selectOption_2_Value"
value="false">
<span class="custom-toggle-checkbox-slider"></span>
</label>
.....
我还尝试使用元素的完整xpath,但有多个标签具有相同的类名,我希望避免使用完整xpath定位器
我的问题是如何根据其子ID选择正确的标签?如果要根据同级
@ID
选择span
,输入
试试
//label[input[@id='selectOption_1_Value']]/span
或
谢谢,这正是我要找的,也更改了问题的标题以反映您所描述的内容:)
//label[input[@id='selectOption_1_Value']]/span
//input[@id='selectOption_1_Value']/following-sibling::span