Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save algotrader-dotcom/60a591867e6783ba21f5 to your computer and use it in GitHub Desktop.
Save algotrader-dotcom/60a591867e6783ba21f5 to your computer and use it in GitHub Desktop.
Selenium webdriver wait for ajax with Python
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
def ajax_complete(driver):
try:
return 0 == driver.execute_script("return jQuery.active")
except WebDriverException:
pass
def my_automation_test():
ff_driver = webdriver.Firefox()
ff_driver.get("http://domain.tld")
#wait for ajax items to load
WebDriverWait(ff_driver, 10).until(
ajax_complete, "Timeout waiting for page to load")
assert "ajax loaded string" in ff_driver.page_source
@hl2055
Copy link

hl2055 commented Aug 29, 2017

I think it's better to use return not driver.execute_script("return jQuery && jQuery.active") instead of passing exception.

@formynet
Copy link

formynet commented Oct 9, 2017

Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment