Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Selenium Interview Question 3 – Difference Between get() and navigate() Methods of Selenium WebDriver

Posted on 02/19/2025 By admin

In this post we will see an important and confusing topic – Difference between get() and navigate() methods. In fact this is not at all confusing as people just do not try to observe behavior by writing some lines of code and going through official documents.

Let me point down some differences which you people generally see :-

  1. get() method holds or waits till page is loaded while navigate() does not.
  2. get() method does not retain any browsing history while navigate() does.

In fact both above points are incorrect.

First of all navigate() method can not be used directly to load a URL. WebDriver interface has a method “navigate()” which returns a type Navigation which is an inner interface in WebDriver interface. Navigation interface is an abstraction allowing the driver to access the browser’s history by explicit methods and to navigate to a given URL.

This Navigation interface consists of below methods :-

// Move back a single "item" in the browser's history
void back(); 
// Move a single "item" forward in the browser's history. Does nothing if 
we are on the latest page viewed.
void forward();
// Load a new web page in the current browser window. Similar to get() method
void to(String url); 
// Overloaded version of to(String url) that makes it easy to pass in a URL
void to(URL url);  
//Refresh the current page 
void refresh(); 

Referring official document of Selenium is always good to learn valid points. It clearly says get() method is synonyms for to() method. It makes sense that both methods do the same thing.

It defines get() as :

” Load a new web page in the current browser window. This is done using an HTTP POST operation, and the method will block until the load is complete. Synonym for WebDriver.Navigation.to(String)

Let’s see how they define to() method:

“Load a new web page in the current browser window. This is done using an HTTP POST operation, and the method will block until the load is complete. “

Note – You will see in above doc, Selenium developers have mentioned as “This is done using an HTTP GET” which is incorrect. It is actually a POST request. I have reported this typo. You can find that bug details here.

So hopefully you must have got the point that to() and get() are same. In fact to() calls get() method internally.

Go to RemoteWebDriver class of Selenium WebDriver and check implementation of get() method:

In the same class, there is an inner class called “RemoteNavigation” which implements Navigation interface. This class defines methods to(), refresh(), back() and forward(). Check implementation of to().

If still you are confused then some lines of codes will work for sure.

In below program, I am loading same website using get() and to() methods and keeping timer.

package com.automationpractice.testScripts;

import java.util.Date;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DemoTest {

        
        public static void main(String[] args) {
                
                System.setProperty("webdriver.chrome.driver", "G:\\MakeSeleniumEasy\\MakeSeleniumEasyHybridFramework\\exefiles\\chromedriver.exe");
                WebDriver driver = new ChromeDriver();
                
                // Using get() method
                System.out.println("Start Time :"+new Date());
                driver.get("http://makeseleniumeasy.com/");
                System.out.println("End Time :"+new Date());
                driver.quit();
                
                // Using to() method
                driver = new ChromeDriver();
                System.out.println("Start Time :"+new Date());
                driver.navigate().to("http://makeseleniumeasy.com/");
                System.out.println("End Time :"+new Date());
                driver.quit();
                
        }
        
        
        
}

Output:

Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 16407
Only local connections are allowed.
Feb 03, 2019 10:54:53 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Start Time :Sun Feb 03 10:54:53 IST 2019
End Time :Sun Feb 03 10:55:37 IST 2019
Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 37609
Only local connections are allowed.
Feb 03, 2019 10:55:52 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Start Time :Sun Feb 03 10:55:52 IST 2019
End Time :Sun Feb 03 10:56:39 IST 2019

You can see get() and to() both waited till page is loaded. But I am sad that my website loads slow. 🙁

Then question is still up that what is actual difference between get() and navigate(). Answer comes from official document again.

Since navigate has access on browser’s history, you can navigate back and forward as we do in a browser manually by clicking back and forward button. It also provides you to refresh the currently loaded page.

There is another interesting catch here. If you understand here that if a load a URL using to() method then only you can navigate back and forward, its NOT correct. I see people say that get() does not keep history while navigate() does. It is not like that.

Every URL loaded in browser will be in browser history and navigate allows to access that history. So below code will work absolutely fine:

driver.get("http://makeseleniumeasy.com/");
driver.get("https://www.google.com/");
driver.navigate().back();

Difference between get() and navigate():

  1. Return type of get() is void while return type of navigate() is a Navigation interface which allows you use other methods.
  2. Using navigate() you get direct methods of Navigation interface to access browsing history by using back() and forward() methods. You can navigate to a URL as well as you can refresh current window. Using get() it is not possible to go back and forward without passing URL explicitly.
  3. There is no difference in internal implementation of get() and to() as to() method calls get() method internally.

You can download/clone above sample project from here.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: Advanced Concept of Selenium – Design Patterns in Selenium WebDriver – There is Not Only Page Object Model Design Pattern
Next Post: TestNG Tutorials 63: Dependency in TestNG – Usage of Regular Expressions with DependsOnGroup

Related Posts

How To Solve – IllegalArgumentException: Keys to send should be a not null CharSequence Uncategorized
Make Selenium Easy – Page 52 of 52 – Uncategorized
May 25, 2018 – Make Selenium Easy Uncategorized
January 5, 2019 – Make Selenium Easy Uncategorized
Selenium Archives – Page 2 of 3 – Make Selenium Easy Uncategorized
Storing Web Table With Pagination Data Into List Of Map – Java Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark