Selenium wait.until to check ajax completed request - throw error


in selenium Webdriver with Python, I want to wait for the Ajax request (jquery library) to complete. I am using the wait.until () function for Selenium. Ajax request is launched after clicking submitJquery button.

wait.until(self.driver.execute_script("return jQuery.active == 0")) 

but I got the following error:

 E ====================================================================== ERROR: test_MahsumAkbasNet_Pass (__main__.TestClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\xxx\src\unittestpackage\JavaScriptExec.py", line 24, in test_MahsumAkbasNet_Pass wait.until(self.driver.execute_script("return jQuery.active == 0")) File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 66, in until value = method(self._driver) TypeError: 'bool' object is not callable ---------------------------------------------------------------------- Ran 1 test in 14.449s FAILED (errors=1) 

full code:

 # -*- coding: UTF-8 -*- import unittest import time import datetime from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC class TestClass(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.set_page_load_timeout(30) self.driver.maximize_window() def test_MahsumAkbasNet_Pass(self): wait = WebDriverWait(self.driver, 30) self.driver.get("http://www.mahsumakbas.net/selenium") self.driver.find_element_by_id("submitJquery").click() wait.until(self.driver.execute_script("return jQuery.active == 0")) print "Jquery is completed" def tearDown(self): self.driver.close() if __name__ == '__main__': unittest.main() 

Thanks in advance.

+6
source share
1 answer

You need to pass the wait.until() call:

 wait.until(lambda driver: driver.execute_script("return jQuery.active == 0")) 
+8
source

All Articles