Selenium-WebDriver: Browser Navigation Methods

To test any web application, It is important to know how users will navigate through it. Whenever we open URLs in the browser and take any action on the page, the control takes us to the respective page, So to get back to the original page sometimes we have to make the browser back and forth, and the page refresh manually.

When it comes to automation, the selenium WebDriver provides  Browser Navigation Methods which can be mainly used for navigating into the browser. Let’s see the methods listed below.

  • Navigate To Method
  • Forward Method
  • Back Method
  • Refresh Method

Navigation is actually a collection of methods. We need to mention navigate() along with the methods as shown in the below image. Navigate method is implemented under the navigation interface. This allows the driver method to hit the URL in a browser, move into history in the browser, and refresh a browser web page.

The navigate to method is used for opening a String https URL request in a new window and open a new web page in the current browser window. It works the same as get()method in the selenium browser method.
void navigate().to(String URL);
here, void represents return type(which means it returns nothing), navigate() and  to() represents method names which has defined under the  navigation interface. (String URL) represents string type URL input we have to pass in it.
Code Snippet:


Forward Method:

Navigate to forward method is used to navigate to a page one step further based on the browser's history. In a browser with a newly opened page and no recent forward history at that time, we were unable to use the forward method.
void navigate().forward();
Here, void represents return type, navigate() represents method name, forward() represents method name defined under navigation interface.
Code Snippet:


Back Method:

The back method is used for navigating to go one window history back according to browser history. Simply we can use it to go to the previous page we visited.
void navigate().back();
Here, void is return type, navigate() represents method name, back() represents method name defined under navigation interface.
Code Snippet:


Refresh Method:

Navigate refresh method is used to refresh a current open web page in a browser.
void navigate().refresh();
Here, void represents return type,  navigate() represents method name and refresh() represents method name defined under navigation interface.
Code Snippet:


Let's combine all methods and see one example in a code snippet.

public class Ex_Navigation_Methods {
	public static void main(String[] args) {
    //Set Property and giving path of browser path from device folder.
        //driver object declaration
		WebDriver driver = new ChromeDriver();
//navigate().to() >> this method we can use for opening another window


/*navigate().back() ..>> method use for go back to the previous page or go back to one current history*/


//go to one history forward on web page

//for refreshing web page


Visit this link for more information and to explore this topic. Stay tuned for the next blog.

Ganesh Chavan

Ganesh Chavan

QA Test Engineer at