Python Selenium: I am getting element is not attached to the page document error

后端 未结 2 1754
余生分开走
余生分开走 2021-01-29 07:05

I am trying to build a scraper using selenium package for python but I am getting this error:

Message: stale element reference: element is not attached to the pag         


        
2条回答
  •  醉话见心
    2021-01-29 07:30

    Before you attempt to interact with the desired elements you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategy:

    import selenium
    driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
    titles=[]
    for link in links:
      driver.get(link)
      data = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class = 'question-hyperlink']")))
      titles.append(data[0].text)
    

提交回复
热议问题