简体   繁体   中英

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.

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

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:
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.

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 .

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.


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 :

  • Using 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 :

     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:

复选框

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM