Navigation Methods in Webdriver with Examples


Navigate.To(URL)


This method 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.


Parameters: URL – It should be a fully qualified URL.


Navigate.Back()
To move back a single "item" in the web browser's history. And it will not perform any action if you are on the first page viewed.



In the above example, to work with navigate back method, we atleast need to travel to one single page in the browser history.



The first page we have opened is facebook.com page and then traveled to forgot password page. Now the browser has two pages in the history. If we now use navigate.back(), it will redirect the user to facebook.com page.

Navigate.Forward()

To move a single "item" forward in the web browser's history. And it will not perform any action if we are on the latest page viewed.

In the above example, to work with navigate forward method, we atleast need to travel to one or multiple pages in the browser history.

The first page we have opened is facebook.com page and then traveled to forgot password page. Now the browser has two pages in the history. If we now use navigate.back(), it will redirect the user to facebook.com page.
And now again if we navigate.forward(), it will redirect the user to forgot password page.

Navigate.Refresh()

It refreshes the current web page


Below is the sample code to perform page refresh using Action Driver class

There are few scenarios where we need to check if the data is getting cleared once when the page refreshes. And for few websites , it will display an alert when the user tries to refresh the page without saving the form which user has entered data.

In the above example, we are just refreshing the web page after entering the values using sendkeys().