【问题标题】:ElementClickInterceptedException Selenium unable to click button Python [duplicate]ElementClickInterceptedException Selenium 无法单击按钮 Python [重复]
【发布时间】:2020-10-16 22:55:53
【问题描述】:

我正在编写一个单击页面上特定按钮的 selenium 测试。页面上没有其他按钮,但似乎已被遮挡,因此代码无法找到它。

  • 我已尝试将页面最大化,希望它能找到按钮,但无法找到

我的代码

driver.maximize_window()

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='save' and @name='save'][@value='View Report']"))).click()

元素的副本

<input type="submit" value="View Report" id="save" name="save" data-reportid="108">
    

错误

selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素在点 (1750, 770) 处不可点击。其他元素会收到点击:... (会话信息:chrome=83.0.4103.116)

【问题讨论】:

标签: selenium selenium-webdriver


【解决方案1】:

我认为另一个元素可能与你的元素重叠,你应该等待这一层的隐形。该层可以是加载框架或其他任何东西。

WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "selector_for_ovelapped_layer")))

然后点击你需要的元素

另外,您可以使用操作:

element = driver.find_element_by_xpath("//input[@id='save' and @name='save'][@value='View Report']")
webdriver.ActionChains(driver).move_to_element(element).click(element).perform()

你可以用 JSExecutor 来做到这一点:

element = driver.find_element_by_xpath("//input[@id='save' and @name='save'][@value='View Report']")
driver.execute_script("arguments[0].click();", element)

【讨论】:

  • 谢谢。所以我不再收到任何错误消息,但似乎没有正确单击按钮。通常,当单击按钮时,它会将您带到下一页,但没有任何反应,它完成了执行。 @Norayr
  • 在这种情况下,你可以使用我在回答中提到的JSExecutor的点击
猜你喜欢
  • 2020-07-30
  • 1970-01-01
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 1970-01-01
  • 2014-07-14
  • 2021-09-11
  • 1970-01-01
相关资源
最近更新 更多