from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWaitbrowser = webdriver.Firefox()browser.get("http://testsite.com")element = WebDriverWait(browser, 10).until(lambda browser : browser.find_element_by_id("element"))element.click() # it actually goes to page http://testsite.com/test-page.htmlprint "Just clicked! And I'm expecting timeout error!"new_element = WebDriverWait(browser, 0.1).until(lambda browser : browser.find_element_by_id("element"))print "Too bad there's no timeout error, why?!"
OK, as you can see even I set wait time to 0.1 sec there's still no timeout exception thrown. When element.click()
executed it does not block till the whole page loads up and that's why Just clicked! And I'm expecting timeout error!
showed up, and to my surprise new_element = WebDriverWait(browser, 0.1).until(lambda browser : browser.find_element_by_id("element"))
wait till the whole page loads up. And if you use implicit waits
, you get the same result.
My point is, sometimes after you click an element it might take up to even hours for a page to load up because of a bad proxy, and you obviously DO NOT want to wait that long, what you want is a timeout exception. In this case how would you make it work?