ElementClickInterceptedException: Message: element click intercepted: Element amp;lt;labelamp;gt; is not clickable with Selenium and Python(ElementClickInterceptedException:Message:Element Click Intercepted:Elementamp;lt;Labelamp;无法使用Selenium和Python单击) -
问题描述
我正在尝试单击"所有主题"和"所有州"复选框,然后搜索结果。当我运行该脚本时,一个大小为1036x674的铬色窗口打开。 如果不使用窗口,则会出现元素单击拦截错误。如果最小化或最大化窗口,我的脚本运行正常。
我使用的是Selenium 3.141.0、Chrome 76、chromeDriver 76和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:Message:Element Click Intercepted:
元素<;标签for="dnn_ctr81355_StateNetDB_ckBxAllTopics">.<;/label>在点(259665)处不可单击。
其他元素将收到点击:
<;Label for="dnn_ctr81355_StateNetDB_ckBxTopics_0">.<;/label>
(会话信息:Chrome=76.0.3809.100)要单击的复选框就在我尝试单击的复选框的正下方。
推荐答案
您需要
WebDriverWait确定元素visibility_of_element_located,然后滚动到Searchable Database节,xpath即可使用Locator Byxpath。请导入:
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:Message:Element Click Intercepted:Element&;lt;Label&;>无法使用Selenium和Python单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ElementClickInterceptedException:Message:Element Click Intercepted:Element&;lt;Label&;>无法使用Selenium和Python单击
基础教程推荐
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
