Difference between Webdriver get() and navigate()
In the previous post, we have seen how to work with different browsers in selenium. In this post,we will see the difference between Webdriver get() and navigate().
We will use Firefox browser in our demos. The same methods will work for all other browsers.
There are 2 ways, you can open the application in the browser.
- get() method
- navigate() method
1. get() method:
After opening the browser, we need to use the below method to open any particular application. This methods requires the URL of the application.
e.g. Valid is http://www.gmail.com
Invalid is www.gmail.com
Code for using get method to open Gmail application:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class OpenBrowsers { private static WebDriver driver; public static void main(String[] args) { driver = new FirefoxDriver(); driver.get("http://www.gmail.com"); } }
2. navigate() method:
This is another method which can be used to open the application.
Code for using navigate function to open application:
import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class OpenBrowsers { private static WebDriver driver; public static void main(String[] args) { driver = new FirefoxDriver(); driver.navigate().to("http://www.gmail.com"); } }
What is the difference between get() method and navigate() method?
The difference is that if you use navigate, it allows you to go forth and back into history of the browser,refresh the browser etc. It is not possible if using get() method.
2 Responses
[…] Difference between Webdriver get() and navigate() […]
[…] the previous post, we have seen the difference between WebDriver get() and navigate() method. In this post, we will write the first program in […]