My previous question was Selenium Python - Access next pages of search results
After successfully doing this for one keyword, i need to read these keywords line by line from a file, and keep on searching.
file1 = open("M:/Users/Cyborg/Desktop/Py/read.txt","r")
the url is http://www.nice.org.uk/
driver.switch_to_default_content()
str2 = file1.readline()
inputElement = driver.find_element_by_name("searchText")
inputElement.clear()
inputElement.send_keys(str2)
this reads the keyword to be searched from the file, then enters it in the search box.
inputElement.submit()
submits the query. It's pretty much the same as in the question I asked before, and everything works perfectly if str2 is static, that is I define str2='abc'
instead of reading from file. However as soon as I try to read from file and continue searching, I get this error
File "M:\Users\Cyborg\Desktop\Py\test.py", line 22, in <module>
inputElement.submit()
.
.
.
.
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: 'Element not found in the cache - perhaps the page has changed since it was looked up' ;
For some reason I get this error.
Any help would be greatly appreciated!