SELENIUM Navigation Commands Forward, Backward, Refresh

SELENIUM Navigation Commands Forward, Backward, Refresh

In this article, we will look into some of the navigation commands in the selenium webdriver.

But Before that,

What is Navigation command and why use them?

Navigation command is used to perform some actions like forward, backward on our web browser.

To use these navigation commands we use the Navigate interface. It has methods to move back, forward as well as to refresh a web page.

Now let’s look into all this command in more details

Forward Command: navigate().forward()

This command lets the user navigate to the next web page with reference to the browser’s history.

Command – driver.navigate().forward();

Back Command: navigate().back()

The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history. 

Command – driver.navigate().back();

Refresh Command: navigate().refresh() 

This command lets the user refresh the current web page thereby reloading all the web elements. 

Command – driver.navigate().refresh();

Navigate to Command: navigate().to(URL)

This command lets the user launch a new web browser window and navigate to the specified URL. 

Sample code: 

To understand this practically Let's do one sample exercise

1)  Navigate to Google Home page
2)  Enter selenium in the search box and enter
3)  Refresh the next page
4)  Come back again to the Google Home page. 

Below is the code snapshot for this exercise : 



My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post