Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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
Python 使用Selenium选中所有复选框_Python_Python 3.x_Selenium_Checkbox - Fatal编程技术网

Python 使用Selenium选中所有复选框

Python 使用Selenium选中所有复选框,python,python-3.x,selenium,checkbox,Python,Python 3.x,Selenium,Checkbox,我尝试在页面上选中所有复选框,类似于 我试着用它来做这件事 checkboxes = driver.find_elements_by_class_name('gwt-CheckBox') for checkbox in checkboxes: if not checkbox.is_selected(): checkbox.click() 但是,对于是否已选择(),所有复选框都给出False,因此已选择的将关闭,未选择的将打开。下面是一个复选框类(库名称)和一个未选中复选

我尝试在页面上选中所有复选框,类似于

我试着用它来做这件事

checkboxes = driver.find_elements_by_class_name('gwt-CheckBox')
for checkbox in checkboxes:
    if not checkbox.is_selected():
        checkbox.click()
但是,对于
是否已选择()
,所有复选框都给出False,因此已选择的将关闭,未选择的将打开。下面是一个复选框类(库名称)和一个未选中复选框类(成对的标称长度)的示例

如何检查是否已选择这些选项

  <div style="position: relative; display: inline-block; vertical-align: top; float: left;">
   <span class="gwt-CheckBox">
    <input id="gwt-uid-27" tabindex="0" type="checkbox" value="on"/>
    <label for="gwt-uid-27">
     Library name
    </label>
   </span>
  </div>
 </div>
 <div class="holderFp" style="width: 100%; position: relative; overflow: hidden; display: block;">
  <div style="position: relative; display: inline-block; vertical-align: top; float: left; width: 25%;">
   <span class="gwt-CheckBox">
    <input id="gwt-uid-28" tabindex="0" type="checkbox" value="on"/>
    <label for="gwt-uid-28">
     Paired nominal length
    </label>
   </span>
  </div>

库名
成对标称长度

看起来复选框元素实际上在
子标记中。试着使用它

checkboxes = driver.find_elements_by_css_selector('.gwt-CheckBox > input')
你能试试“值”这个属性吗?猜测所选复选框的值=“on”!