【问题标题】:ElementClickInterceptedException: element click intercepted. Other element would receive the click: Selenium PythonElementClickInterceptedException:元素点击被拦截。其他元素会收到点击:Selenium Python
【发布时间】:2021-10-08 08:12:08
【问题描述】:

我已经看到有关此错误的其他问题,但我的情况是在我的程序中,其他元素应该收到点击。详细信息:网络驱动程序正在通过谷歌搜索滚动,它必须点击它找到的每个网站,但程序阻止了这一点。我怎样才能让它不搜索它点击的上一个网站?

这就是函数。程序正在循环它,在第一个循环之后它向下滚动并发生错误:

def get_info():
browser.switch_to.window(browser.window_handles[2])
description = WebDriverWait(browser, 10).until(
    EC.presence_of_element_located((By.TAG_NAME, "h3"))
).text

site = WebDriverWait(browser, 10).until(
    EC.presence_of_element_located((By.TAG_NAME, "cite"))
)
site.click()

url=browser.current_url
#removes the https:// and the / of the url
#to get just the domain of the website
try:
    link=url.split("https://")
    link1=link[1].split("/")
    link2=link1[0]
    link3=link2.split("www.")
    real_link=link3[1]

except IndexError:
    link=url.split("https://")
    link1=link[1].split("/")
    real_link=link1[0]

time.sleep(3)
screenshot=browser.save_screenshot("photos/"+"(" + real_link + ")" + ".png")
global content
content=[]
content.append(real_link)
content.append(description)
print(content)
browser.back()
time.sleep(5)
browser.execute_script("window.scrollBy(0,400)","")
time.sleep(5)

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver automation


    【解决方案1】:

    您可以创建一个被点击的网站列表,并检查每次该链接是否被点击。这是演示代码:

    clicked_website=[]
    
    url=browser.current_url
    clicked_website.append(url)
    
    # Now while clicking
    if <new_url> not in clicked_website:
        <>.click()
    

    这只是一个想法如何实施。你的代码乱七八糟,我没看清楚,你自己在你的代码中实现吧。

    【讨论】:

      猜你喜欢
      • 2019-11-08
      • 2019-12-29
      • 2021-09-04
      • 2021-04-17
      • 2019-09-24
      • 2021-08-26
      • 2016-06-08
      • 2017-04-16
      • 2020-01-04
      相关资源
      最近更新 更多