【发布时间】:2019-09-24 16:51:21
【问题描述】:
我正在通过单击“是”创建一个单击单选按钮的测试
单选按钮代码:
<div role="group" class="btn-group btn-group-toggle">
<label class="btn btn-primary">
<input name=".product2" autocomplete="off" value="true" type="radio"> Yes </label>
我已经试过了:
time.sleep(3)
driver.find_element_by_css_selector("input[name*='product2'] [value='true']").click();
但它返回一个错误:
元素<input name=".product2" type="radio"> 无法滚动到视图中
还有其他选择器可以用来点击“是”吗? 还是使用 css 选择器缺少细节?
我也试过find_element_by xpath,结果还是一样。
【问题讨论】:
-
如果该元素在当前窗口中不可见,则首先您需要滚动到该位置,然后您可以选择单选按钮。这是可能的解决方案stackoverflow.com/a/41744403/2845389