title: Selenium Python : StaleElementReferenceException when reading from file and using the word as search query
body: <p>My previous question was <a href="https://stackoverflow.com/questions/24166689/selenium-python-access-next-pages-of-search-results">Selenium Python - Access next pages of search results</a></p>
  
  <p>After successfully doing this for one keyword, i need to read these keywords line by line from a file, and keep on searching.</p>
  
  <pre><code>file1 = open("M:/Users/Cyborg/Desktop/Py/read.txt","r")
  </code></pre>
  
  <p>the url is <a href="http://www.nice.org.uk/" rel="nofollow noreferrer">http://www.nice.org.uk/</a></p>
  
  <pre><code>driver.switch_to_default_content()
  str2 = file1.readline()
  inputElement = driver.find_element_by_name("searchText")
  inputElement.clear()
  inputElement.send_keys(str2)
  </code></pre>
  
  <p>this reads the keyword to be searched from the file, then enters it in the search box.</p>
  
  <pre><code>inputElement.submit()
  </code></pre>
  
  <p>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 <code>str2='abc'</code> instead of reading from file. However as soon as I try to read from file and continue searching, I get this error</p>
  
  <pre><code>File "M:\Users\Cyborg\Desktop\Py\test.py", line 22, in &lt;module&gt;
      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' ;
  </code></pre>
  
  <p>For some reason I get this error.</p>
  
  <p>Any help would be greatly appreciated!</p>