Wait for page redirect Selenium WebDriver (Python)
<p>I have a page which loads dynamic content with ajax and then redirects after a certain amount of time (not fixed). How can i force selenium webdriver to wait for the page to redirect then immediately after go to a different link?</p>

<pre><code>import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome();
driver.get("http://www.website.com/wait.php") 
</code></pre>

<p>You can create a custom <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow">Expected Condition to wait</a> for the URL to change:</p>

<pre><code>from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

wait = WebDriverWait(driver, 10)
wait.until(lambda driver: driver.current_url != "http://www.website.com/wait.php")
</code></pre>

<p>The Expected Condition is basically a <em>callable</em> - you can <a href="http://stackoverflow.com/a/29377790/771848">wrap it into a class</a> overwriting the <code>__call__()</code> magic method as the built-in conditions are implemented.</p>

python selenium selenium-webdriver webdriver