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单击
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
