Message: stale element reference: element is not attached to the page document (Session info: chrome=83.0.4103.61)

Question:

how can I use WebDriverWait(driver, 10) for this code?
because I cant not extract data for more than one page


    ff=['https://www.oddsportal.com/soccer/england/premier-league-2017-2018/tottenham-manchester-city-ddkDE7Ld/#over-under;2','https://www.oddsportal.com/soccer/england/premier-league-2017-2018/burnley-bournemouth-xSUUEVHO/#over-under;2']
    webD=wb.Chrome(r'C:UsersPERSONLDownloadschromedriver_win32 (1)chromedriver.exe')
    k=len(ff)
    for i in range(k):
        webD.get(ff[i])
        c03= webD.find_elements_by_class_name('bt-2')
        c05=c03.find_elements_by_class_name('table-container')
        c04=c03.find_elements_by_tag_name('strong')
        kk.append(c04)

        
    fla=kk[0]

    print(fla)
    for i in fla:
        m=i.text
        num.append(m)

Asked By: HaAbs

||

Answers:

There is only one webelement having class ‘bt-2’, so it should be webD.find_element_by_class_name (without the “s” in elements). This line should anyway be rewritten as

c03 = WebDriverWait(webD, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'bt-2')))

Also you can iterate the ff list of urls like this, rather than using range/indexes (it’s more pythonic):

num=[]
for url in ff:
    driver.get(url)
    c03 = WebDriverWait(webD, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'bt-2')))
    c05 = c03.find_elements_by_class_name('table-container')
    c04 = c03.find_elements_by_tag_name('strong')
    for i in c04:
        print(i.text)
        num.append(i.text)
Answered By: 0buz
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.