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.

  1. get() method
  2. navigate() method

get and naviagate

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.

driver.get(“URL of the application”);

Don't Forget Note Means Important Remember Forgetting

URL should start with Http: instead of WWW. If URL starts with ‘WWW’, then selenium does not open it.
e.g. Valid is http://www.gmail.com
Invalid is www.gmail.com

Code for using get method to open Gmail application:


2. navigate() method:

This is another method which can be used to open the application.

driver.navigate().to(“URL of application”);

Code for using navigate function to open application:


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.

driver.navigate().back(); // Perform backward function of browser
driver.navigate().forward();  // Perform forward function of browser
driver.navigate().refresh(); //refresh the browser

 

Ask Question
Have any question or suggestion for us?Please feel free to post in  Q&A Forum

 

Print Friendly, PDF & Email
Working with different browsers in selenium
Difference between findElement() and findElements()
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

2 Responses

  1. August 16, 2015

    […] Difference between Webdriver get() and navigate() […]

  2. August 16, 2015

    […] the previous post, we have seen the difference between WebDriver get() and navigate() method. In this post, we will write the first program in […]

Leave a Reply

Your email address will not be published. Required fields are marked *