A
A
Andris_habrahabr2017-04-09 14:40:43
Python
Andris_habrahabr, 2017-04-09 14:40:43

How to track the completion of all ajax requests on a website page using selenium?

I am learning how to do page UI testing with selenium.
The page has a lot of ajax requests that are executed on load, the problem is that I can't programmatically track when they complete.
I am using this construct:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


timeout = 5
wait = WebDriverWait(driver, timeout)
my_tag_present = EC.visibility_of_element_located((By.TAG_NAME, "my_tag"))
wait.until(my_tag_present)

this approach works, but not always, and I have to specify a specific tag (tag_id, class, xpath).
I would like to apply a more complex and universal approach, without specifying the necessary tags.
How, for example, site testing services work. After all, it (the service) does not know what elements should be on the page, however, we see the total loading time and a screenshot of the loaded page in the report.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Grigoriev, 2017-04-09
@Vaindante

driver.execute_script("return jQuery.active == 0")

A
Andrey Rodkin, 2017-04-13
@anrodkin

Boolean areAjaxRequestsCompleted = driver.execute_script("return (typeof($) === 'undefined') ? true : !$.active;")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question