title: How to find an element dynamically loaded by jQuery in page through Selenium, WebDriver and Python
body: <p>I'm having a problem getting an item within a page, this item is loaded after loading the page via <strong>ajax</strong> or <strong>iframe</strong>, is there any way to create a condition for the script to wait until the item appear?</p>
  
  <p>To exemplify my problem I did the following test:</p>
  
  <p><strong>Python:</strong></p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as EC
  from selenium.webdriver.common.by import By
  from selenium.common.exceptions import TimeoutException
  browser = webdriver.Firefox()
  browser.get("http://localhost/test_time.php")
  delay = 10 # seconds
  try:
      myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, 'id_2'))) 
      print ("Elememento encontrado")
  except TimeoutException:
      print ('Nao foi dessa vez :(')
      pass
  </code></pre>
  
  <p>I search for <strong>id_2</strong> which is displayed 5 seconds after completion of loading the page by JavaScript</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
      &lt;title&gt;Teste Python&lt;/title&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          function sleep(milliseconds) {
              var start = new Date().getTime();
              for (var i = 0; i &lt; 1e7; i++) {
                  if ((new Date().getTime() - start) &gt; milliseconds){
                  break;
                  }
              }
          }
          $( document ).ready(function() {
              console.log('js start');     
              sleep(5000);
              jQuery('&lt;div&gt; DIV 2 &lt;/div&gt;', {id: 'id_2', }).appendTo('#content');                      
              console.log('js Done');                 
          });
      &lt;/script&gt;    
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;Main page&lt;/div&gt;
      &lt;div id='content'&gt;
          &lt;div id="id_1"&gt;DIV 1&lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is the HTML I have 2 <strong>div</strong> if you do the search for <strong>div id_1</strong> it finds no problem, but the <strong>div id_2</strong> which is displayed 5 seconds after page loading is not found by selenium even though I determine the wait time of 10 seconds.</p>
  
  <p>I would like a light to find a solution to this problem.</p>