我有下面的标签,这是多个选择选项按钮的标签,每个选择都有它的div,里面有一个标签,然后在该标签内有一个ID,我需要用它来确定我想要哪个 Selenium 点击。
<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>
.....
我只是尝试过,但该元素在这一点上不可交互。我需要单击 span 元素才能选择位于 label 元素下的它
xpath = //*[@id='selectOption_1_Value']
我还尝试使用元素的完整 xpath,但有多个具有相同类名的标签,我想避免使用完整的 xpath 定位器。
我的问题是如何根据子 ID 选择正确的标签?
最佳答案
如果您想根据同级input
的@id
选择span
,请尝试
//label[input[@id='selectOption_1_Value']]/span
或
//input[@id='selectOption_1_Value']/following-sibling::span
关于selenium - 如何根据同级输入的@id选择跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66210932/