title: Selenium: Wait until text in WebElement changes
body: <p>I'm using <code>selenium</code> with Python 2.7. to retrieve the contents from a search box on a webpage. The search box dynamically retrieves and displays the results in the box itself.</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  import pandas as pd
  import re
  from time import sleep
  
  driver = webdriver.Firefox()
  driver.get(url)
  
  df = pd.read_csv("read.csv")
  
  def crawl(isin):
      searchkey = driver.find_element_by_name("searchkey")
      searchkey.clear()
      searchkey.send_keys(isin)
      sleep(11)
  
      search_result = driver.find_element_by_class_name("ac_results")
      names = re.match(r"^.*(?=(\())", search_result.text).group().encode("utf-8")
      product_id = re.findall(r"((?&lt;=\()[0-9]*)", search_result.text)
      return pd.Series([product_id, names])
  
  df[["insref", "name"]] = df["ISIN"].apply(crawl)
  
  print df
  </code></pre>
  
  <p>Relevant part of the code may be found under <code>def crawl(isin):</code></p>
  
  <ul>
  <li>The program enters what to search for in the search box (<em>the box is badly named as</em> <code>searchkey</code>). </li>
  <li>It then does <code>sleep()</code> and waits for the content to show in the search box dropdown field <code>ac_results</code>.</li>
  <li>Then gets two variables <code>insrefs</code> and <code>names</code> with Regex.</li>
  </ul>
  
  <p>Instead of calling <code>sleep()</code>, I would like for it to wait for the content in the WebElement <code>ac_results</code> to load.</p>
  
  <p>Since it will continuously use the search box to get new data by entering new search terms from a list, one could perhaps use Regex to identify when there is new content in <code>ac_results</code> that is not identical to the previous content.</p>
  
  <p>Is there a method for this? It is important to note that the content in the search box is dynamically loaded, so the function would have to recognise that something has changed in the WebElement.</p>