【问题标题】:Unable to click radio element in a browser (using Python 3 and Selenium) [duplicate]无法在浏览器中单击单选元素(使用 Python 3 和 Selenium)[重复]
【发布时间】:2019-09-10 09:56:46
【问题描述】:

我正在使用 Python 3 并使用 Selenium 单击浏览器中的单选按钮。我能够找到要单击的 Radio Element。但是,当我做Element.click() 时,它给了我一个错误:

Message: unknown error: Element <Description of Element> is not clickable at point (340, 190).

Other element would receive the click: <Description of some other element>.  

在浏览器中显示的单选元素是:

<input data-val="true" data-val-required="Required" id="Promoter" name="Type" onchange="Checkboxck(&#39;Promoter&#39;)" type="radio" value="Promoter" />

我找到这个单选元素并点击它的代码是:

Registered_Project_RadioButton = browser.find_element_by_id("Promoter")
Registered_Project_RadioButton.click()

【问题讨论】:

  • 您需要关闭其他元素或等到它消失,例如正在加载...弹出窗口、浮动标题、对话框等

标签: python-3.x selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

使用 Actions 类或 Java Script Executor 来实现。

from selenium.webdriver.common.action_chains import ActionChains

Registered_Project_RadioButton = browser.find_element_by_id("Promoter")
ActionChains(browser).move_to_element(Registered_Project_RadioButton).click().perform()

Registered_Project_RadioButton = browser.find_element_by_id("Promoter")
browser.execute_script("arguments[0].click();", Registered_Project_RadioButton)

【讨论】:

  • 感谢昆杜克。第一个选项不起作用,但第二个解决方案起作用了。谢谢..:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-26
  • 2019-02-19
  • 2020-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多