wait for page load in selenium java code example
Example 1: wait until page loads selenium javascript
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver=webdriver.Firefox()
driver.get("http://www.example.com")
try:
elem=WebDriverWait(driver,10).until(
EC.presence_of_element_located((By.ID,"Element_to_be_found"))
)
finally:
driver.quit()
Example 2: wait until page loads selenium javascript
<span class="kn">from selenium import webdriver
from</span> <span class="nn">selenium.webdriver.common.by</span> <span class="k">import</span> <span class="n">By</span>
<span class="kn">from</span> <span class="nn">selenium.webdriver.support.ui</span> <span class="k">import</span> <span class="n">WebDriverWait</span>
<span class="kn">from</span> <span class="nn">selenium.webdriver.support</span> <span class="k">import</span> <span class="n">expected_conditions</span> <span class="k">as</span> <span class="n">EC</span>
<span class="n">driver</span> <span class="o">=</span> <span class="n">webdriver</span><span class="o">.</span><span class="n">Firefox</span><span class="p">()</span>
<span class="n">driver</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"http://www.example.com"</span><span class="p">)
<span class="k">try</span><span class="p">:</span>
<span class="n">elem </span><span class="o">=</span> <span class="n">WebDriverWait</span><span class="p">(</span><span class="n">driver</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span><span class="o">.</span><span class="n">until</span><span class="p">(</span>
<span class="n">EC</span><span class="o">.</span><span class="n">presence_of_element_located</span><span class="p">((</span><span class="n">By</span><span class="o">.</span><span class="n">ID</span><span class="p">,</span> <span class="s2">"Element_to_be_found"</span><span class="p">))
<span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">driver</span><span class="o">.</span><span class="n">quit</span><span class="p">()</span>