Difference between driver.get() and driver.navigate().to() methods!

First step in any automation Test script is to launch the browser and navigate to the Application Under Test. When it comes to Selenium, there are 2 methods.

            1. driver.get("URL")
            2. driver.navigate().to("URL")

Difference between driver.get() and driver.navigate().to() methods


Some of the Automation Testers are confused with these 2 statements. This post details the difference between these 2 methods.

Method#01: driver.get()

This method navigates to the specific URL and wait until the page is completely loaded. This method makes the WebDriver wait until the page is completely loaded and then returns control to your script. The main reason for using this method is that the modern days Websites are heavily using AJAX and we are not sure how long it'll take the page to completely load.

Return Type of this method is "void"






Method#02: driver.navigate().to()

This method just navigates to the application URL and it'll not wait until the page is loaded. This method is not recommended for modern days application as they are heavily depending on AJAX/ API Calls.

But, this method maintains the navigation history in Cookies and can be used whenever needed.

Return Type Method is "Navigation" where "Navigation" is an interface. This Navigation interface maintains History of the browser actions your performed post the execution of this method.

Examples:

driver.navigate().forward()
driver.navigate().back()
driver.navigate().refresh()

Syntax: driver.navigate().to("http://software-testing-community.blogspot.com/")
SHARE

About அமரகோசம்

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment