简体   繁体   English

ElementClickInterceptedException: 消息: 元素点击被拦截: <label>Selenium 和 Python 无法点击</label>元素

[英]ElementClickInterceptedException: Message: element click intercepted: Element <label> is not clickable with Selenium and Python

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.当我运行脚本时,会打开一个 1036x674 大小的 chrome 窗口。

If I leave the window alone, I get element click interception errors.如果我不理会窗口,我会收到元素点击拦截错误。 If I minimize or maximize the window, my script works fine.如果我最小化或最大化窗口,我的脚本工作正常。

I am using Selenium 3.141.0, chrome 76, chromedriver 76, and python 3.6我正在使用 Selenium 3.141.0、chrome 76、chromedriver 76 和 python 3.6

chromedriver_path = r"C:\Users\path\to\chromedriver.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()

But I get this error:但我收到此错误:

ElementClickInterceptedException: Message: element click intercepted: ElementClickInterceptedException:消息:元素点击被拦截:
Element <label for="dnn_ctr81355_StateNetDB_ckBxAllTopics">...</label> is not clickable at point (259, 665).元素 <label for="dnn_ctr81355_StateNetDB_ckBxAllTopics">...</label> 在点 (259, 665) 处不可点击。
Other element would receive the click:其他元素将收到点击:
<label for="dnn_ctr81355_StateNetDB_ckBxTopics_0">...</label> <label for="dnn_ctr81355_StateNetDB_ckBxTopics_0">...</label>
(Session info: chrome=76.0.3809.100) (会话信息:chrome=76.0.3809.100)

The CheckBox that would be clicked is right below the one I am trying to click.将被单击的复选框位于我要单击的复选框的正下方。

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 .您需要WebDriverWait来确保元素visibility_of_element_located ,然后滚动到Searchable Database部分,您可以通过xpath使用定位器。

Please import :请导入:

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

Try the bellow code.试试下面的代码。

chromedriver_path = r"C:\Users\path\to\chromedriver.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()

This error message...这个错误信息...

ElementClickInterceptedException: Message: element click intercepted

...implies that the click method invoked on the desired element was intercepted by some other element. ...暗示在所需元素上调用的click方法被其他某个元素拦截


To click() on the checkboxes associated with text as All Topics and All States you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :要将与文本关联的复选框上的click()作为所有主题所有状态,您必须为element_to_be_clickable()引入WebDriverWait ,您可以使用以下任一定位器策略

  • Using CSS_SELECTOR :使用CSS_SELECTOR

     driver.get("http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for$='_StateNetDB_ckBxAllTopics']"))).click() driver.find_element_by_css_selector("label[for$='_StateNetDB_ckBxAllStates']").click()
  • Using XPATH :使用XPATH

     driver.get("http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[contains(@for, '_StateNetDB_ckBxAllTopics')]"))).click() driver.find_element_by_xpath("//label[contains(@for, '_StateNetDB_ckBxAllStates')]").click()
  • Browser Snapshot:浏览器快照:

复选框

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素不可点击 Selenium 和 Python - selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python ElementClickInterceptedException:消息:元素单击拦截元素不可单击错误单击使用 Selenium 和 Python 的单选按钮 - ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python ElementClickInterceptedException:消息:元素点击被拦截: - ElementClickInterceptedException: Message: element click intercepted: ElementClickInterceptedException:元素点击被拦截:使用 Selenium Python 单击搜索按钮时,元素不可点击 - ElementClickInterceptedException: element click intercepted: Element is not clickable at point error clicking on Search button using Selenium Python selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截 - selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted ElementClickInterceptedException:消息:使用 Selenium WebDriver 拦截元素点击 - ElementClickInterceptedException: Message: element click intercepted using Selenium WebDriver selenium.common.exceptions.ElementClickInterceptedException:消息:使用 Selenium 单击单选按钮时元素单击被截获错误 - selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted error clicking on a radiobutton using Selenium Python ElementClickInterceptedException: 元素点击被拦截。 其他元素会收到点击:Selenium Python - ElementClickInterceptedException: element click intercepted. Other element would receive the click: Selenium Python Selenium - 元素点击被拦截:元素在点不可点击 - Selenium - element click intercepted: Element is not clickable at point ElementClickInterceptedException:消息:元素单击被拦截 - 如何在 for 循环中定位并切换到 iframe - ElementClickInterceptedException: Message: element click intercepted - how to locate and switch to iframe in a for loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM