元素点击被截获(点击完美工作)(selenium python)(弹出)

2024-10-02 22:26:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python selenium自动化一个网站

# ----- click on the sign up popup
popup = driver.find_element_by_xpath("/html/body/div[1]/div[4]/section[1]/div/div/div[2]/div/p/a")
popup.click()

单击工作正常,弹出消息显示完美。但在那之后,我得到了这个错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a href="#mailmunch-pop-940306" class="btn-link btn-auto btn-intro btn-primary">...</a> is not clickable at point (1263, 589). Other element would receive the click: <div class="mailmunch-inner-overlay" id="mailmunch-inner-overlay-178218df563cebd"></div>
  (Session info: chrome=89.0.4389.82)

代码停止工作。我能做什么? 请帮忙


Tags: thediv网站onseleniumelementclassclick
3条回答

在您尝试从弹出窗口中查找元素后,是否会收到所述错误?所以产生错误的不是你所想的那条线。如果是这种情况,那么当您尝试(例如)单击该弹出窗口中的某个内容时,请尝试以下操作:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,""))).click()

您需要导入:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
popup = driver.find_element_by_xpath("/html/body/div[1]/div[4]/section[1]/div/div/div[2]/div/p/a")
driver.execute_script("arguments[0].click();", popup)

尝试调用直接单击元素,使其绕过覆盖或单击其关闭按钮

你需要去掉覆盖层。没有HTML,我只能提供几个解决方案:

  • 找到覆盖的“取消”按钮,单击它
  • 使用Javascript从DOM中删除覆盖
  • 等待覆盖层消失

相关问题 更多 >