坚持确定复选框已选中以在 selenium webdriver & python 中进行测试
Stuck to determine the checkbox is checked to test in selenium webdriver & python
我想确定是否选中了我正在测试的网页的复选框。我正在使用 Selenium&Python。
网页Html片段:
<input class="ng-untouched ng-pristine ng-valid" _ngcontent-ddp-11="" name="printInput" type="checkbox"/>
当我尝试时
chkbox_status = eachDiv.find_element_by_xpath("//*[@class='ng-untouched ng-pristine ng-valid']").get_attribute("checked")
它总是 return True
。
这里有人可以帮助确定复选框状态吗?
可以使用is_selected()
方法:
eachDiv.find_element_by_xpath("//*[@class='ng-untouched ng-pristine ng-valid']").is_selected()
如果复选框被选中,这将 return boolean
True
否则 False
另请注意,您正在尝试将 get_attribute()
应用于 list
- 它不能 return 您 True
,而是 AttributeError
我想确定是否选中了我正在测试的网页的复选框。我正在使用 Selenium&Python。
网页Html片段:
<input class="ng-untouched ng-pristine ng-valid" _ngcontent-ddp-11="" name="printInput" type="checkbox"/>
当我尝试时
chkbox_status = eachDiv.find_element_by_xpath("//*[@class='ng-untouched ng-pristine ng-valid']").get_attribute("checked")
它总是 return True
。
这里有人可以帮助确定复选框状态吗?
可以使用is_selected()
方法:
eachDiv.find_element_by_xpath("//*[@class='ng-untouched ng-pristine ng-valid']").is_selected()
如果复选框被选中,这将 return boolean
True
否则 False
另请注意,您正在尝试将 get_attribute()
应用于 list
- 它不能 return 您 True
,而是 AttributeError