Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 如何根据同级输入的@id选择span_Selenium_Testing_Xpath - Fatal编程技术网

Selenium 如何根据同级输入的@id选择span

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

我有下面的标签,这是一个用于多个选择选项按钮的标签,每个选择都有其on div,其中有一个标签,然后在该标签中有一个ID,我需要使用该ID来确定要单击哪个选项

<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