Skip to content
Advertisement

How do I stop my scraper from hitting an error whenever it clicks the next button?

Hello so i’m trying to scrape next page on google shopping website. But i get an error whenever my scraper clicks the next button. It stops working when it loads the next page.

Here’s my codeblock

JavaScript

next_page = driver.find_element(By.XPATH, ‘//*[@id=”pnnext”]’) next_page.click()

HERE’S THE ERROR I GET

Traceback (most recent call last): File “c:UsersLPDocumentspythonwedgwoodwedgwood.py”, line 50, in name = card.find_element(By.CLASS_NAME, ‘OSrXXb’).text.strip()

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

Advertisement

Answer

That error means when it’s looking for that element ‘OSrXXb’ it can’t find it. You have a bunch of other elements wrapped in try blocks but it seems this one you expect to be there and it isn’t.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement