I am writing a selenium script that will get all filenames in every directory on a website. My approach to that is to make a list of directory objects and .click() every directory in the list one by one to access all filenames. The problem I face is Selenium does not allow me to click on the next directory after the 1st. The following code is my approach...
folders = driver.find_elements_by_class_name("directory")
for folder in folders:
folder.click()
time.sleep(2)
# click below is to navigate back to root directory
driver.find_element_by_xpath('//*[@id="default-layout"]/div[1]/div/div/div[1]/div[1]/nav/ol/a').click()
time.sleep(2)
With the above code, I get the following error when Selenium tries to click on the 2nd directory in the list... selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document