【问题标题】:Python Selenium ElementClickInterceptedExceptionPython Selenium ElementClickInterceptedException
【发布时间】:2021-06-15 21:51:18
【问题描述】:

在 Selenium 的帮助下,我已经尝试了几种方法来单击特定网站上的链接。所有这些都会导致以下错误消息:

ElementClickInterceptedException:消息:元素单击被拦截:元素 LMGP06050001 在点 (159, 364) 处不可单击。其他元素会收到点击:... (会话信息:chrome=89.0.4389.90)

我做错了什么?

目标是到达以下站点并从那里获取一些数据: https://www.lipidmaps.org/data/LMSDRecord.php?LMID=LMGP06050001

到目前为止,在我的代码下方:

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

PATH = "C:\\Users\\xxxxxx\\anaconda3\\chromedriver.exe"
browser = webdriver.Chrome(PATH)

browser.get("https://www.lipidmaps.org/data/structure/LMSDSearch.php?Mode=ProcessClassSearch&LMID=LMGP0605")

link = browser.find_element_by_link_text("LMGP06050001")
browser.implicitly_wait(5)
link.click()

【问题讨论】:

    标签: python selenium webdriver selenium-chromedriver webdriverwait


    【解决方案1】:

    您遇到该问题的原因是出现了cookie 弹出窗口,您需要先接受 cookie。

    使用WebDriverWait() 并等待 element_to_be_clickable()

    browser.get("https://www.lipidmaps.org/data/structure/LMSDSearch.php?Mode=ProcessClassSearch&LMID=LMGP0605")
    
    #Accept to cookie
    WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button#cookie_notice_accept"))).click()
    
    WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.LINK_TEXT,"LMGP06050001"))).click()
    

    您需要导入以下库

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    

    【讨论】:

      猜你喜欢
      • 2022-08-14
      • 2020-07-11
      • 2021-11-03
      • 1970-01-01
      • 2020-10-16
      • 2020-09-09
      • 2021-09-13
      • 1970-01-01
      • 2018-07-17
      相关资源
      最近更新 更多