URL Loading in Selenium Webdriver: All about get() and navigate()

Hello Folks,

We have learnt how to open Chrome, Firefox, IE and Edge browser. It is very first step before we start automating test cases through Selenium Webdriver.

Second step is to load URL of AUT(Application Under Test). So in this post we will learn below topics:

  1. Opening a URL through get() method.
  2. Opening a URL using to() method.
  3. Difference between get() and navigate()

Opening a URL through get() method:

Most common way of loading a URL in browser in Selenium is using get() method.

Syntax:  void get(java.lang.String url)

Points to know about get():

  1. get() method is declared in WebDriver interface.
  2. get() method is defined in RemoteWebDriver class.
  3. get() method returns void.
  4. get() method takes an argument of type String which is your AUT URL.
  5. It loads a new web page in the current browser window.
  6. It is done using an HTTP GET operation.
  7. It blocks the execution of next statement till web page is loaded completely.
  8. If you try to open a URL without http or https( e.g. driver.get(“www.facebook.com”);) , get() method will throw “org.openqa.selenium.WebDriverException“. It will also give error message as “Cannot navigate to invalid URL”.
  9. You can load a URL as http://facebook.com. It will not give any exception. Normally also it will load Facebook page. This was asked to me in interview.
  10. If you pass a wrong URL e.g. https://faceok.com , it will not give any page load time exception. Browser will display “ERR_CONNECTION_REFUSED” and program will be terminated. It was asked to me in interview.
  11. There is default page load time which is 300 seconds. It will throw  org.openqa.selenium.TimeoutException once default page load time reaches and page is still loading.
  12. If a URL is being loaded and you stop manually loading of URL by clicking on “Stop Loading Page” icon what will happen?? Nothing will happen and get() method will hold the control till default page load timeout reaches. You can’t make get() method fool. It is also an interview question.
  13. We can set page load time using pageLoadTimeout(long arg0, TimeUnit arg2) method. Syntax is as below:

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

14. You can not go back and forward using get() method. You can use get() multiple times in a                  program.

Complete JAVA Program:


In above program, I am setting page load time once Facebook is loaded. New page load time will be applicable from next statement. Remember execution of JAVA programs goes line by line. I am setting less page load time to get exception.

Opening a URL using to() method.

  • We can load a URL using to() method of Navigation inner interface of WebDriver interface.
  • It is similar to get() method and to() method calls get() method internally.

  • Syntax: driver.navigate().to(“http://www.makeseleniumeasy.com”);
  • navigate() is abstract method which allows the driver to access the browser’s history and to navigate to a given URL. It returns a WebDriver.Navigation that allows the selection of what to do next.
  • It behaves in same way as get() method does.
  • Using navigate() method we can go back and forward using back() and forward() methods respectively if any session presents.
  • forward() method moves a single “item” forward in the browser’s history. Does nothing if we are on the latest page viewed.
  • back() method moves back a single “item” in the browser’s history.
  • Using navigate() method we can refresh the page by calling refresh() method on it.
  • We can pass URL class object as well to to() method to open a URL. to() method is overloaded with arguments type of String and URL(java.net.URL).
  • Syntax: driver.navigate().to(new URL(“http://www.google.com”));

Complete JAVA Program:


Difference between get() and navigate():

  1. get() method does not allow driver to access the browser’s history while navigate() allows the driver to access the browser’s history and to navigate to a given URL.
  2. You can not navigate back and forward using get() while same can be achieved through navigate().
  3. There is no specific method for refresh a web page in get() while navigate() provides a method named refresh(). You can refresh a page using get() also by calling get() method again. It was interview question. How you will refresh a page using get() method.

That’s it guys. I hope you must have learnt some new things. If you have any doubt or suggestions, feel free to contact me.

Thank you.



Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning