【问题标题】:Unable to click on Radio Button getting "ElementClickInterceptedException" error无法单击单选按钮,出现“ElementClickInterceptedException”错误
【发布时间】:2021-05-22 15:28:49
【问题描述】:

尝试在 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()

有没有办法解决这个问题?我尝试了多种方法,但无法执行任务。

【问题讨论】:

    标签: python selenium webdriverwait splinter expected-condition


    【解决方案1】:

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

    btn = driver.find_element_by_xpath('//input[@name = "gender"]')
    driver.execute_script("arguments[0].click();", btn)
    

    另外,考虑使用WebDriverWait 而不是隐式等待。

    【讨论】:

    • 谢谢,它成功了。你能解释一下为什么我们使用参数[0]
    • 这是 javascript 语法。把它想象成 - 你传递给脚本的第一个参数是你的btn。其他人有explained it better than me
    猜你喜欢
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多