Python Forum

Full Version: selenium.wait_for_condition equivalent in Python bindings for WebDriver
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Currently, it isn’t possible to use wait for condition Currently it isn’t possible to use wait_for_condition with WebDriver. The python selenium code does provide the DrivenSelenium class for accessing the old selenium methods, but it can’t do wait_for_condition. The selenium wild has some info on that.
Your best bet is to use the WebDriverWait class. This is a helper class that periodically executes a function waiting for it to return True. My general usage is
Skip code block
driver = webdriver.Firefox()
driver.get(‘https://example.com’)
add = driver.find_element_by id(“ajax_button”)
add. click() source = driver.page_source
def compare_source(driver):
try:
return source != driver.page_source
except WebDriverException:
pass
WebDriverWait(driver, 5).until(compare_source)
# and now do some assertions
This solution is by no means ideal.. The try/except is necessary for situations where the page request/response cycle is delayed waiting for some ajax activity to complete.
If compare_source get’s called in the midst of the request/response cycle it’ll throw a WebDriverException. The test coverage for WebDriverWait is also helpful to look at.
have you tried waiting for an element that is only located on the loaded page?
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
...
WebDriverWait(driverr, 5).until(EC.presence_of_element_located((By.ID,"IDName")))