I want to automate a script which verify certain contents in the webpage.
The login page redirected several times before landing on an application page and these redirects were causing issues occasionally. The issue was definately related to timing. So how can webdriver wait until the final page is fully loaded or settled ?
A typical solution is to wait for an element on the target page to become available. Unfortunately, we use 100+ unique urls therefore there is no predictable landing page.
So how can an ExpectedCondition be implemented, that waits for the application to stabilize with respect to redirects ?
The main agenda is, I have a set of URL's and i wanted to verify that all these URL's are valid by checking the content in it. All these are direct URL's of learning contents to which my organization has partnered eg Lynda, skillsoft,etc. So when we launch these URL through automated scrip first it will ask authentication(My organizational credential) and after that it will redirect to corresponding sites. During these redirect, in certain cases there is multiple redirection happening and finally the content page is loaded. This is the scenario. My script fails mainly due to the wait i guess
We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method. We have to pass return document.
How can I ask the Selenium-WebDriver to wait for few seconds in Java? To tell the Selenium WebDriver to wait for a specified amount of time use Thread. sleep. This will tell Java to pause execution of the test for the specified number of milliseconds.
Navigate to URL: https://www.testandquiz.com/selenium/testing.html. Click on the "This is a link" link (This link will redirect you to the javaTpoint website) Come back to the Home page using the back command. Again go back to the javaTpoint website using forward command.
As you mentioned multiple redirection happening and finally the content page is loaded
and the script fails mainly due to the wait
is pretty much possible. In these cases we need to induce ExplicitWait
i.e. WebDriverWait
with expected_conditions
clause set to either of the following :
urlToBe
: An expectation for checking the current url is an exact match.
new WebDriverWait(driver, 10).until(ExpectedConditions.urlToBe("https://www.facebook.com/"));
urlContains
: An expectation for checking that the current url contains a case-sensitive substring.
new WebDriverWait(driver, 10).until(ExpectedConditions.urlContains("facebook"));
urlMatches
: An expectation for checking the current url pattern is the expected pattern which must be an exact match.
new WebDriverWait(driver, 10).until(ExpectedConditions.urlMatches("my_regex"));
url_to_be
: An expectation for the URL of the current page to be a specific url.
WebDriverWait(driver, 10).until(EC.url_to_be("https://www.google.co.in/"))
url_matches
: An expectation for the URL to match a specific regular expression.
WebDriverWait(driver, 10).until(EC.url_matches("my_regex"))
url_contains
: An expectation for the URL of the current page to contain specific text.
WebDriverWait(driver, 10).until(EC.url_contains("google"))
url_changes
: An expectation for checking the current url which must not be an exact match.
WebDriverWait(driver, 10).until(EC.url_changes("https://www.google.co.in/"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With