What is the difference between driver.get() and driver.navigate() in Selenium?
This article will present you with a complete idea about the difference between driver.get() & driver.navigate() and usage of these commands in selenium webdriver.
Basically, both methods are used for the same purpose and the purpose is to navigate on URL and open a web page .It is done using an HTTP GET request operation and the method will block until the load is complete.
driver.get() method is used to open or navigate on an URL and it will wait till the whole page gets loaded so webDriver will wait until the page has fully loaded before returning control to the test case.
if the web page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use waits.
driver.get() command doesn’t maintain the browser History and cookies
Practically navigate().to() and get() do exactly the same thing i.e. to load a given URL in the browser window.
Navigate Method allows for the browser to move forward(as per browser history) ,Back (as per browser history), Refresh or to open any link so basically It maintains browser history or cookies to navigate back or forward.
Below command will launch a new web browser window and navigate to the specified URL.
“navigate()” method returns the instance of the Navigation interface. This interface provides a lot of additional functionalities other than just loading a URL in the Webpage
below are the additional features provided by this interface:
This command will refresh the current web page there by reloading all the web elements.
This command will take back the user to the previous webpage in the web browser’s history.
This command will navigate to the next web page with reference to the browser’s history.