How to get Selenium to wait for a transition page to redirect before running an assertion

霸气de小男生 提交于 2019-11-29 03:04:27

A simple approach would be wait for some "particular" text on that final page, see "waitForText" command for further info on it

josh-cain

To add to John's approach, you can use the Selenium wait mechanism to verify that elements on your final page are present like so:

Java:

WebDriverWait wait = new WebDriverWait(webDriver, 10); // seconds
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("foo")));

Ruby:

wait = Selenium::WebDriver::Wait.new(timeout: 10) # seconds
wait.until { driver.find_element(id: "foo") }

This will properly follow any redirects involved.

Example from https://code.google.com/p/selenium/wiki/RubyBindings

You could call wait_for_page twice in a row. The first waits for the redirect, the second for the final page.

You can also wait until the page title is an expected value:

$driver->wait()->until(WebDriverExpectedCondition::titleIs('New page title from redirect'));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!