Answer the question
In order to leave comments, you need to log in
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
Оставь слип - так проще
или
www.obeythetestinggoat.com/how-to-get-selenium-to-...
изучайте API класса WebDriverWait selenium-python.readthedocs.io/waits.html
while True:
try:
btn = driver.find_element_бла_бла()
btn.click()
break
except NoSuchElementException:
continue
А вы не пробовали смотреть в сторону реализации ожиданий?
После авторизации пишите ожидание появления нужного элемента (ссылки) и только после этого клик.
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 questionAsk a Question
731 491 924 answers to any question