python - 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,但它并没有解决这个问题
解决方案
另一个有趣的解决方法是通过 javascript 执行该点击- 在这种情况下,它前面的内容或阻止它都无关紧要:
submit_button = driver.find_element_by_id("submitButton")
driver.execute_script("arguments[0].click();", submit_button)
另外,请注意常规 selenium 点击和通过 javascript 点击之间的区别:
推荐阅读
- c# - 抽象 .NET Core 3 应用程序启动问题
- javascript - 如果后端服务器已关闭,那么如何使用 Axios 在 Reactjs 中进行处理
- list - Prolog - 从列表中删除具有相同第一个值的对
- powershell - PowerShell:是否必须将脚本模块保存在与目录相同的名称中
- pandas - DataFrame 对象没有属性插入
- sql-server - 使用 asp.net mvc 时如何将表单的详细信息提交到数据库?
- ruby - 安装 redmine 插件时出错
- localization - 如何编写全局函数以在 Angular 6 中的所有组件中使用
- php - PHP date_default_timezone_set() 未返回预期结果
- javascript - Object.keys 返回空数组