What possibly can be the difference between Selenium Webdriver , Get and Navigate ?

Is there any difference between Get() and Navigate() at all?


This is a very confusing question. And you would often encounter this in your job interviews .




What is driver.get("URL") ?


The Webdriver gets a URL to load a page in the browser .
Hence using driver.get command to do so sounds good. Isn,t it ?
driver.get("http://www.google.com");


What does driver.navigate().to("URL") do?



This command also navigates to a URL in the browser .

Now we can possibly give any URL with get() and it will load that particular page in your browser .
Then why on earth do I need to use driver.navigate ? 

You might be wondering.
Practically while working in a project, we often use get() and navigate() interchangeably in some scenarios.

Mostly when we need to navigate/load a page we use :


  • driver.get("URL") OR
  • driver.navigate().to("URL")


Then why do we need both of them ? When we could have just used one, and the work was done ?
Friends although both are same in terms that they take you to a page in the browser, but there is still a difference here.


Difference between Get() and Navigate()

The catch is , while driver.navigate().to("URL") just opens that particular website in the browser, but driver.get("URL") waits there till the complete page is loaded in the browser. Until then it does not return the control to the script.

Note : If there many ajax calls in the current page which webdriver is loading, then webdriver may not know when it has loaded completely. That time to make sure pages are fully loaded then you need to use " wait " .
Also if 


Add-Ons with Navigate()

The navigate interface also has the ability to move backwards and forwards in your browser’s history:
driver.navigate().refresh();
driver.navigate().forward();
driver.navigate().back();

Note: We can also use Actions class of WebDriver to perform page refresh
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.F5).perform();