[英]ElementClickInterceptedException: element click intercepted. Other element would receive the click: Selenium Python
I have seen other questions about this error but my case is that in my program the other element should receive the click.我已经看到有关此错误的其他问题,但我的情况是,在我的程序中,另一个元素应该收到点击。 In details: the webdriver is scrolling through google search and it must click every website it finds but the program is preventing that.
详细说明:webdriver 正在滚动谷歌搜索,它必须点击它找到的每个网站,但程序阻止了它。 How can I make it NOT search the previous site it clicked?
我怎样才能让它不搜索它点击的上一个网站?
This is the function.这就是功能。 The program is looping it and after the first loop it scrolls down and the error occurs:
程序正在循环它,在第一个循环之后它向下滚动并发生错误:
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)
You can create a list of clicked website and check every time if that link is clicked or not.您可以创建一个点击过的网站列表,并在每次点击该链接时检查。 Here's the demo code :
这是演示代码:
clicked_website=[]
url=browser.current_url
clicked_website.append(url)
# Now while clicking
if <new_url> not in clicked_website:
<>.click()
This is just an idea how to implement.这只是一个如何实施的想法。 Your code is mess, I didn't understand clearly so, implement in your code by yourself.
你的代码一团糟,我没看明白,你自己在代码中实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.