I
I
Ivan Petrov2017-01-31 00:37:12
Python
Ivan Petrov, 2017-01-31 00:37:12

Selenium how to wait for page reload?

I'm trying to make a test for the site, authorization and immediately exit.
The problem is that login and logout starts with a click on the same element, and then a pop-up menu appears.
At first I log in, everything is fine, but then selenium tries to click on the same element immediately after authorization so that a pop-up menu appears with a link to log out.
He does not find the link, since the page starts to reload and the pop-up menu for the authorized user simply did not appear, but will appear only after the reload.
Putting sleep(1) between login and log out works fine.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
sim3x, 2017-01-31
@sim3x

Оставь слип - так проще
или
www.obeythetestinggoat.com/how-to-get-selenium-to-...

S
shamanovski, 2017-01-31
@shamanovski

изучайте API класса WebDriverWait selenium-python.readthedocs.io/waits.html

Дмитрий, 2017-01-31
@LazyTalent

while True:
    try:
        btn = driver.find_element_бла_бла()
        btn.click()
        break
    except NoSuchElementException:
        continue

Талик, 2017-01-31
@Talik0507

А вы не пробовали смотреть в сторону реализации ожиданий?
После авторизации пишите ожидание появления нужного элемента (ссылки) и только после этого клик.
https://seleniumhq.github.io/selenium/docs/api/jav...
WebElement dynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("dynamicElement_id")));
Селениум сам отслеживает полную загрузку страницы, потому можно попробовать изменить ожидание загрузки страницы.
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question