ElementClickInterceptedException:消息:元素点击被拦截:元素<标签&

ElementClickInterceptedException: Message: element click intercepted: Element lt;labelgt; is not clickable with Selenium and Python(ElementClickInterceptedException:消息:元素点击被拦截:元素lt;标签gt;Selenium 和 Python 不可点击) - IT屋-程序
本文介绍了ElementClickInterceptedException:消息:元素点击被拦截:元素<标签>Selenium 和 Python 不可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试单击所有主题"和所有状态"复选框,然后搜索结果.当我运行脚本时,会打开一个大小为 1036x674 的 chrome 窗口.

I am trying to click on the "All Topics" and "All States" CheckBoxes then search the results. When I run the script, a chrome window opens up in size 1036x674.

如果我不理会窗口,我会收到元素点击拦截错误.如果我最小化或最大化窗口,我的脚本可以正常工作.

If I leave the window alone, I get element click interception errors. If I minimize or maximize the window, my script works fine.

我正在使用 Selenium 3.141.0、chrome 76、chromedriver 76 和 python 3.6

I am using Selenium 3.141.0, chrome 76, chromedriver 76, and python 3.6

chromedriver_path = r"C:Userspath	ochromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"

topics_xpath = "//*[@id="dnn_ctr81355_StateNetDB_UpdatePanel1"]/div[1]/div[2]/span/label"
states_xpath = "//*[@id="dnn_ctr81355_StateNetDB_UpdatePanel1"]/div[2]/div[2]/span/label"
browser.get(url)
time.sleep(30)

elem = browser.find_element_by_xpath(topics_xpath)
elem.click()
time.sleep(5)
elem = browser.find_element_by_xpath(states_xpath)
elem.click()

但我得到这个错误:

ElementClickInterceptedException:消息:元素点击被拦截:
元素 在点 (259, 665) 处不可点击.
其他元素会收到点击:

ElementClickInterceptedException: Message: element click intercepted:
Element <label for="dnn_ctr81355_StateNetDB_ckBxAllTopics">...</label> is not clickable at point (259, 665).
Other element would receive the click:
<label for="dnn_ctr81355_StateNetDB_ckBxTopics_0">...</label>
(Session info: chrome=76.0.3809.100)

将被点击的复选框就在我试图点击的复选框的正下方.

The CheckBox that would be clicked is right below the one I am trying to click.

推荐答案

你需要WebDriverWait来确定元素visibility_of_element_located,然后滚动到Searchable Database 部分,您可以通过 xpath 使用定位器.

You need WebDriverWait to make sure the element visibility_of_element_located, then scroll to Searchable Database section, and you can use locator by xpath.

请导入:

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

试试下面的代码.

chromedriver_path = r"C:Userspath	ochromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"

topics_xpath = "//div[@class='divTopicsSection1']//span//label[text()='All Topics']"
states_xpath = "//div[@class='divStatesSection1']//span//label[text()='All States']"
dBase_xpath = "//h4[text()='Searchable Database']"
browser.get(url)
WebDriverWait(browser, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, topics_xpath)))
elem = browser.find_element_by_xpath(dBase_xpath)
browser.execute_script("arguments[0].scrollIntoView(true);", elem)

browser.find_element_by_xpath(topics_xpath).click()
browser.find_element_by_xpath(states_xpath).click()

这篇关于ElementClickInterceptedException:消息:元素点击被拦截:元素&lt;标签&gt;Selenium 和 Python 不可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

python count duplicate in list(python在列表中计数重复)
drop_duplicates not working in pandas?(drop_duplicates 在 pandas 中不起作用?)
Get unique items from list of lists?(从列表列表中获取唯一项目?)
How to install python package with a different name using PIP(如何使用 PIP 安装具有不同名称的 python 包)
How to quot;select distinctquot; across multiple data frame columns in pandas?(如何“选择不同的?跨越 pandas 中的多个数据框列?)
Intersection of two lists, keeping duplicates in the first list(两个列表的交集,在第一个列表中保留重复项)