python - ElementClickInterceptedException:元素点击被拦截。其他元素会收到点击:Selenium Python
问题描述
我已经看到有关此错误的其他问题,但我的情况是在我的程序中,其他元素应该收到点击。详细信息:网络驱动程序正在通过谷歌搜索滚动,它必须点击它找到的每个网站,但程序阻止了这一点。我怎样才能让它不搜索它点击的上一个站点?
这就是功能。程序正在循环它,在第一个循环之后它向下滚动并发生错误:
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)
解决方案
您可以创建点击网站列表,并检查每次是否点击该链接。这是演示代码:
clicked_website=[]
url=browser.current_url
clicked_website.append(url)
# Now while clicking
if <new_url> not in clicked_website:
<>.click()
这只是一个如何实施的想法。你的代码乱七八糟,我没看清楚,自己在你的代码中实现。
推荐阅读
- unity3d - 如何在 ARCore 生成的平面上沿相机视图方向移动对象/预制件
- c - 如何在 C 中按如下方式打印模式?
- html5-canvas - fabric.js 在保持深度的同时移动图像?
- pandas - 如何从 value_counts() 的输出创建新的数据框
- database - Oracle 大对象块存储
- r - 未找到阅读技能数据集
- docker - docker容器的ports信息
- python - Python:在其他输出之前记录打印到控制台的注释
- python - 使用 Anaconda 的 PyVimeo
- typescript - 如何在 Angular 6 中检查 url 是否存在?