【发布时间】:2019-10-03 03:38:23
【问题描述】:
我正在尝试使用find_element_by_xpath 查找所有元素。在下面的网页元素中,我分别寻找这三个元素:
1. <label for="hw-log-mode-none" class="ng-binding">None</label>
2. <label for="hw-log-mode-session" class="ng-binding">Per-Session</label>
3. <label for="hw-log-mode-mapping" class="ng-binding">Per-Mapping</label>
<div class="field ng-scope" ng-if="!isTransparentMode && showNatPool && !policy.isIPv6" ng-show="policy.action == 'accept' && policy.nat == 'enable'">
<label class="ng-binding">Hardware Logging Mode</label>
<div>
<div class="radio-group">
<input type="radio" id="hw-log-mode-none" value="none" ng-model="policy['hw-logging-mode']" class="ng-pristine ng-untouched ng-valid" name="670">
<label for="hw-log-mode-none" class="ng-binding">None</label>
<input type="radio" id="hw-log-mode-session" value="session" ng-model="policy['hw-logging-mode']" class="ng-valid ng-dirty ng-touched" name="671" style="">
<label for="hw-log-mode-session" class="ng-binding">Per-Session</label>
<input type="radio" id="hw-log-mode-mapping" value="mapping" ng-model="policy['hw-logging-mode']" class="ng-valid ng-dirty ng-touched ng-valid-parse" name="672" style="">
<label for="hw-log-mode-mapping" class="ng-binding">Per-Mapping</label>
</div>
</div>
</div>
我可以在上面的列表中找到元素 #1 和 #2。但是当我尝试使用相同的方式查找元素 #3 时:
elem = driver.find_element_by_xpath("//label[@for='hw-log-mode-mapping']")
我收到了这个错误:
消息:元素点击被拦截:元素...不是 在点 (707, 508) 可点击。其他元素会收到点击: ...(会话信息:chrome=77.0.3865.90)
【问题讨论】:
-
您需要添加动态等待,直到元素可点击。你能添加完整的堆栈跟踪吗
-
我不知道动态等待是否是这里的解决方案。页面上的布局可能会阻塞元素。
-
我在 elem.click() 之前添加了一行:time.sleep(1)。但是还是看到这个异常:
标签: python-3.x selenium radio-button