I have a python script that uses selenium. The steps of the script is:
- Login
- Go to a page which starts a file harvester process
- After every 1 minute refresh the status page to check if the file harvester has completed - which is indicated in a table on the page
The problem that I am having is that when the page is refreshed using browser.refresh() I get the following error
Traceback (most recent call last):
File "D:\ScheduledTasks\Scripts\ScriptArchive\COL_INSPIRE\INSPIRE_METADATA_v1.1.py", line 491, in <module>
print head.text
File "C:\Python27\ArcGIS10.2\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 61, in text
return self._execute(Command.GET_ELEMENT_TEXT)['value']
File "C:\Python27\ArcGIS10.2\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 385, in _execute
return self._parent.execute(command, params)
File "C:\Python27\ArcGIS10.2\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "C:\Python27\ArcGIS10.2\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
StaleElementReferenceException: Message: Element not found in the cache - perhaps the page has changed since it was looked up
This used to work, but now the above error is appearing, what is the best way to to "poll" a page to check whether a piece of text has changed.
My code is
header = browser.find_elements(By.TAG_NAME,"tr")
#go through each header to get teh one we want
headerIndex = 0
for head in header:
#print headerIndex
print head.text
if "Next harvest" in head.text:
#Get the table data for the header that we want
tdata = header[headerIndex].find_elements(By.TAG_NAME,"td")
for t in tdata:
print t.text
if "Scheduled" in t.text:
#wait 60 seconds
time.sleep(60)
browser.refresh()
elif "Not yet scheduled" in t.text:
refreshComplete = True
break
if refreshComplete == True:
break
headerIndex = headerIndex + 1