Understanding Selenium WebDriver Navigation Commands?

After successfully running our first test case on Firefox and Chrome. We are stepping towards grasping the essential navigation commands in Selenium. Thus we are going to discuss about multifarious browser commands that we would be using in our day to day automation testing.

Requirement :- 
How to navigate in Browser using Selenium Webdriver?

Solution :-
We are focusing on Get and Navigate Commands.

MindMap for Selenium Navigation commands
Browser Navigation Commands

To Command:-
This command is use to navigate to specific page or URL

Forward Command:-
This command is similar to browser forward button, Takes you forward by one page on the browser’s history.

Back Command:-
Used to go back to previous page like browser’s back button.

Refresh Command:-
Refresh the current page.


Note:- Same can be achieved using "sendkeys"


Get Command:-
Opens  a new browser window and navigate to given URL.

Get v/s Navigate :-
“navigate().to()” and “get()” do exactly the same thing. Only thing is that incase of “get” selenium would wait for the page to fully load before executing the next line of code.

Also “navigate” interface further exposes the ability to move backwards and forwards in your browser’s history.

Let us test the above commands by completing the following Test Scenario:-

  1. Launch Home page using Get Method
  2. Open Contact Us page
  3. Navigate Back to Home Page
  4. Navigate Forward to Contact Us Page 
  5. Refresh the Contact Us Page 
  6. Navigate To Selenium Page
  7. Close the Browser


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
public class Navigation {

public static void main(String[] args) {
//Creating WebDriver Object
System.out.println("Launch Home page using Get Method");
System.setProperty("", "C:\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//Opens the given URL using Get Method
//Click on Contact Us Link
System.out.println("Open Contact Us page");
//Using Back Command, go back to "Home" page
System.out.println("Navigate Back to Home Page");
// Using Forward Command, go to "Contact Us" link
System.out.println("Navigate Forward to Contact Us Page ");
//Refresh the page
System.out.println("Refresh the Contact Us Page ");
//Using To command, open the Selenium Page
System.out.println("Navigate To Selenium Page");
System.out.println("Close the Browser");
//Closing the Browser



2 replies on “Understanding Selenium WebDriver Navigation Commands?”

Leave a Reply

Your email address will not be published. Required fields are marked *