I
I
Ivan Petrov2017-02-05 20:37:05
Python
Ivan Petrov, 2017-02-05 20:37:05

How to wait for ajax to complete and then reload in selenium?

Greetings.
There was such a problem. I'm trying to automate the authorization and logout of the account on the site.
The same button is responsible for these actions, on click a pop-up menu appears, either with an authorization form or with a user menu.
I have authorization in the test and immediately exit the account.
The problem is that an ajax request is first performed and only then authorization and reloading.
It turns out that while the ajax request is being executed, selenium starts the next action - logout , tries to click on the authorization button again and then finds the logout link
How to correctly wait until the ajax request is completed, reload, and only then perform the next action?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2017-02-05
@Toximiner

1. Never use time.sleep()
2. You need to wait until the required element disappears / appears on the page:

wait = WebDriverWait(driver, 20)
wait.until(visibility_of_element_located(locator))

or
selenium-python.readthedocs.io/api.html#module-sel...

D
Dmitry, 2017-02-05
@ipatov_dn

import time
and put time.sleep before the click (the time required to load)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question