ElementClickInterceptedException: Message: element click intercepted: Element

后端 未结 2 1084
独厮守ぢ
独厮守ぢ 2020-11-27 08:38

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.

I

2条回答
  •  执念已碎
    2020-11-27 09:05

    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()
    

提交回复
热议问题