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 9 in Selenium by eslam
• 130 points
337 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
11,328 views
0 votes
1 answer

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,510 points
2,611 views
0 votes
1 answer
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,870 points
2,055 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,870 points
2,164 views