首页 > 解决方案 > python selenium点击被弹出窗口阻止

问题描述

当我尝试单击位于弹出菜单后面的按钮时,我收到以下错误消息。

*** selenium.common.exceptions.ElementClickInterceptedException: Message: Element <input id="submitButton" class="search-button icon-search active" type="submit"> is not clickable at point (729.2000122070312,22) because another element <div id="monetate_lightbox_mask" class=""> obscures it

此错误消息能够识别阻止我点击的内容的名称

我怎样才能得到这个名称(作为一个元素),以便我可以进行修改,例如,

element = <div id="monetate_lightbox_mask" class="">

browser.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element);""", element)

等待功能不适用,因为此弹出窗口不会消失。我已经尝试过 webdriver.ActionChains,但它并没有解决这个问题

标签: pythonselenium

解决方案


另一个有趣的解决方法是通过 javascript 执行该点击- 在这种情况下,它前面的内容或阻止它都无关紧要:

submit_button = driver.find_element_by_id("submitButton")
driver.execute_script("arguments[0].click();", submit_button)

另外,请注意常规 selenium 点击和通过 javascript 点击之间的区别:


推荐阅读