What is the difference between get()
and navigate()
methods?
Does any of this or maybe another method waits for page content to load?
What do I rea
There are some differences between webdriver.get()
and webdriver.navigate()
method.
As per the API Docs get() method in the WebDriver interface extends the SearchContext and is defined 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.
* This will follow redirects issued either by the server or as a meta-redirect from within the
* returned HTML.
* Synonym for {@link org.openqa.selenium.WebDriver.Navigation#to(String)}.
*/
void get(String url);
Usage:
driver.get("https://www.google.com/");
On the other hand, navigate() is the abstraction which allows the WebDriver instance i.e. the driver
to access the browser's history as well as to navigate to a given URL. The methods along with the usage are as follows:
to(java.lang.String url)
: Load a new web page in the current browser window.
driver.navigate().to("https://www.google.com/");
to(java.net.URL url)
: Overloaded version of to(String) that makes it easy to pass in a URL.
refresh()
: Refresh the current page.
driver.navigate().refresh();
back()
: Move back a single "item" in the browser's history.
driver.navigate().back();
forward()
: Move a single "item" forward in the browser's history.
driver.navigate().forward();