【发布时间】:2016-12-27 13:19:04
【问题描述】:
我正在尝试检查页面上的所有复选框,类似于https://sqa.stackexchange.com/questions/3292/how-to-select-or-check-multiple-checkboxes-in-selenium。
我尝试用
checkboxes = driver.find_elements_by_class_name('gwt-CheckBox')
for checkbox in checkboxes:
if not checkbox.is_selected():
checkbox.click()
但是,所有复选框都为 is_selected() 提供 False,因此已选中的复选框将关闭,未选中的复选框将打开。下面我有一个选中的 CheckBox 类(库名称)和一个未选中的 Checkbox 类(成对标称长度)的示例。
如何检查这些是否已被选中?
<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>
【问题讨论】:
-
你可以试试属性“Value”吗?猜测选定复选框的 value="on" !
标签: python python-3.x selenium checkbox