in selenium Webdriver with Python, i want to wait for an Ajax request to completed(jquery library). i use wait.until() function of Selenium. Ajax request is start after click on submitJquery button.
wait.until(self.driver.execute_script("return jQuery.active == 0"))
but i got 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)
complete code is:
# -*- 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.
You need to pass a callable to wait.until()
:
wait.until(lambda driver: driver.execute_script("return jQuery.active == 0"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With