python selenium error element is not attached to the page document

+1 vote

I am scraping Banggood, the problem is that driver open just first link and then doesn't go to next link of links list( next product )

and get this error in line 24

(selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document)

but i tried to print links out of loop i got all of the

print( links[0].get_attribute('href') )
print( links[2].get_attribute('href') )

main code :

import time 
from selenium import webdriver #THIS IS MAIN SCRIPT

driver = webdriver.Chrome(executable_path='C:\\Users\\Compu City\\Desktop\\chromedriver.exe')#DRIVER LOCATION
driver.get('https://usa.banggood.com/Deals_Electronics.html#dealscategories2')#DRIVER LOCATION
driver.implicitly_wait(30)


links = driver.find_elements_by_css_selector('body > div.flashdeals-container.fixed > div.main > div.product-list.cf > ul > li > a.products_name.exclick')
#links has 25 link
product=0
while product <= len(links):

    driver.get(links[product].get_attribute('href'))


    try:# TITLE
        title = driver.find_element_by_css_selector('#centerCtrl > div.title_hd > h2 > strong')
        print(title.text)
    except:
        print('no title')

    try:# NEW PRICE
        new_price = driver.find_element_by_css_selector('#centerCtrl > div.itemBox > div.item_price_box > div.item_now_price')
        print(new_price.text)
    except:
        print('no new price')

    try:# OLD PRICE
        old_price = driver.find_element_by_css_selector('#centerCtrl > div.itemBox > div.item_price_box > div.item_old_price')
        print(old_price.text)
    except:
        print('no old price')

    try:#image
        image = driver.find_element_by_css_selector('#landingImage').get_attribute('src')
        print(image)
    except:
        print('no image')
    product +=1
Apr 10, 2020 in Selenium by eslam
• 130 points
9,807 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

+1 vote
2 answers
+1 vote
2 answers
0 votes
1 answer

To check that the web page is loaded or not using Selenium Web Driver?

The solution is using Implicit Wait which ...READ MORE

answered May 24, 2018 in Selenium by Meci Matt
• 9,460 points
24,795 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,751 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,622 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,697 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,561 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP