In this article, we will discuss different page navigation used in WebDriver automation tests. Mostly, the important things that we do while authoring Selenium tests are Page navigation.
Some of the operations that we do are listed below:
- Navigate between the pages that open during the tests.
- Sometimes we would like to use the browser’s back and forward functionality.
- We might want to refresh the current web page.
We will go through different kinds of navigation within Selenium tests.
To navigate to a webpage with a known URL. For example, if we want to navigate to the Bing search page.
Load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete. This will follow redirects issued either by the server or as a meta-redirect from within the returned HTML.
Webdriver allows using the Navigation interface to access browser history. Navigation is an abstraction allowing the driver to access the browser’s history and to navigate to a given URL.
Move a single “item” forward in the browser’s history. Also,does nothing if we are on the latest page viewed.Useful to go to the next page.If the next page exists, for example if you go back from a page, then want to return to it.
Move back a single “item” in the browser’s history.
To refresh the current page:
Loads a new web page in the current browser window. It uses an HTTP GET request operation, and the method will block until the load is complete.Also, this will follow redirects issued either by the server or as a meta-redirect for example 301 redirects from within the returned HTML.
to() method is overloaded in the Navigation interface. It has two signatures and allows String as well as URL as shown below:
void to(String url);
An overloaded version of that makes it easy to pass in a URL.
void to(URL url);
Selenium Tutorials on this website: