Python,Selenium:元素未附加到页面文档

时间:2019-11-07 13:03:42

标签: python selenium-webdriver

def parse_match(driver, url):
    wait = WebDriverWait(driver, 2)
    driver.get(url)

    hiddens_list = []
    more = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "more")))
    ActionChains(driver).move_to_element(more).perform()

    hiddens = driver.find_elements_by_xpath('//div[contains(@class, "othersList")]')[1].find_elements_by_tag_name('a')

    for hidden in hiddens:
        hiddens_list.append(hidden.text)

    more = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "more")))
    for link in hiddens:
        for name in hiddens_list:
            print(link.text)
            if link.text == name:
                link.click()
                more = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "more")))
                ActionChains(driver).move_to_element(more).perform()
                continue

url ='https://www.oddsportal.com/soccer/england/premier-league/norwich-watford-2ozLgUyq/'

如何单击隐藏列表(<li class="r more">)中的每个元素。

我只能单击第一个链接。然后在第selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document行的第二次迭代中收到错误if link.text == name:

0 个答案:

没有答案