Skip to content

Instantly share code, notes, and snippets.

  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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