What is the use of driver.get(“URL”) and driver.navigate().to(“URL”) commands? Is there any difference between the two?
Hi Mark,
Both driver.get(“URL”) and driver.navigate().to(“URL”) commands are used to navigate to a URL passed as a parameter. There is a minor difference between the two commands-
driver.navigate() allows moving back and forward in browser history with the help of driver.navigate().forward() and driver.navigate().back() commands.
In the case of single-page applications (where the URL is appended by ‘#’ to navigate to different sections of the page)- driver.navigate().to() navigates to a particular section by changing the URL without refreshing the page. Whereas driver.get() refreshes the page.
This refreshing of the page is also the primary reason why history is not maintained in the case of the driver.get() command.