在selenium webdriver&python中选中复选框进行测试

2024-09-29 00:17:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想确定是否选中了我正在测试的网页的复选框。我使用的是Selenium&Python。在

网页Html片段:

<input class="ng-untouched ng-pristine ng-valid" _ngcontent-ddp-11="" name="printInput" type="checkbox"/>

当我试过的时候

^{pr2}$

它总是返回True。在

这里有人能帮助确定复选框的状态吗?在


Tags: name网页inputhtmltypeseleniumngclass
1条回答
网友
1楼 · 发布于 2024-09-29 00:17:45

您可以使用is_selected()方法:

^{1}$

如果复选框被选中,则返回booleanTrue,否则返回{}

还请注意,您试图将get_attribute()应用于list-它不能返回您True,而是返回{}

相关问题 更多 >