无法单击单选按钮出现“ElementClickInterceptedException”错误

问题描述

尝试在 python 中使用 selenium Webdriver 单击单选按钮时出现以下错误

ElementClickInterceptedException: Message: element click intercepted: Element 
<input name="gender" required="" type="radio" id="gender-radio-1" class="custom-control-input" value="Male"> 
is not clickable at point (532,370). Other element would receive the click: <label title="" for="gender-radio-1" class="custom-control-label">...</label>
  (Session info: chrome=88.0.4324.182)

下面是我的代码 页面网址:https://demoqa.com/automation-practice-form

from selenium import webdriver
driver = webdriver.Chrome(executable_path = 'chromedriver')
driver.maximize_window()
driver.get('https://demoqa.com/automation-practice-form')
btn = driver.find_element_by_xpath('//input[@name = "gender"]')
driver.implicitly_wait(7)
btn.click()

有什么办法可以解决这个问题吗?我尝试了多种方法但无法执行任务。

解决方法

尝试通过执行 javascript 来强制点击:

Lazy(Of T)

另外,考虑使用 btn = driver.find_element_by_xpath('//input[@name = "gender"]') driver.execute_script("arguments[0].click();",btn) 而不是隐式等待。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...