My program is throwing an error message "Stale element reference: element is not attached to the page document". When I looked at the previous posts (such as Python Selenium stale element fix),, I found that I am not updating the url after calling click function. I updated the url. However, it didn't fix the issue. Could anyone point out where am I making mistake please? Here is my code:
chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--disable-infobars") driver = webdriver.Chrome(chrome_options=chrome_options,executable_path="path of driver here") driver.get("https://stackoverflow.com/users/37181/alex-gaynor?tab=topactivity") if driver.find_elements_by_xpath("//a[@class='grid--cell fc-white js-notice-close']"): driver.find_element_by_xpath("//a[@class='grid--cell fc-white js-notice-close']").click() inner_tabs = driver.find_elements_by_xpath("//div[@class='tabs']//a") for inner_tab in inner_tabs: if inner_tab.text == "answers": inner_tab.click() time.sleep(3) driver.get(driver.current_url) continue if inner_tab.text == "questions": inner_tab.click() time.sleep(3) driver.get(driver.current_url) continue driver.quit()