I am retrieving my link using the following code:
os.environ['MOZ_HEADLESS'] = '1'
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout)
self.driver = webdriver.Firefox(firefox_binary=binary, executable_path='C:/chromedriver/geckodriver')
self.driver.get(link)
Next, I call:
xpath=".//a[@class='tileLink']"
ignored_exceptions = (NoSuchElementException, StaleElementReferenceException,)
your_element = WebDriverWait(self.driver, 30, ignored_exceptions=ignored_exceptions).until(
expected_conditions.presence_of_element_located((By.XPATH, xpath)))
and then
links = self.driver.find_elements_by_xpath(".//a[@class='tileLink']")
for link in links:
href_ = link.get_attribute("href") # <<-- Error ehre
and link.get_attribute(attribute) throws the stale element exception.
Now, given the WebDriverWait I thought I would avoid this issue, yet it persists.
I am tempted to take the page source, once it has loaded, and throw it into lxml to avoid this issue completely.
The time the passes between establishing links and iterating over the links is a second at most.
Has anyone else experienced an issue like this, and found a solution?
Any guidance is appreciated.
linkslist don't hold anyhrefattributes, so you should use atry-exceptblock to get rid of this problem. - SzabolcsStaleElement, it would be something else completely. I do not think this is accurate. - jason m