Automation QA Testing Course Content

WebDriver Navigate() Methods

naviagte():An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

 1)to("url"):opens the url and maintains the browser history
 We can load a URL using to() method of Navigation inner interface of WebDriver interface.
It is similar to get() method and to() method calls get() method internally.

      public void to(String url) 
      {
RemoteWebDriver.this.get(url);
      }
Syntax: driver.navigate().to(“http://google.com");
navigate() is abstract method which allows the driver to access the browser’s history and to navigate to a given URL. It returns a WebDriver.Navigation that allows the selection of what to do next.
It behaves in same way as get() method does.
Using navigate() method we can go back and forward using back() and forward() methods respectively if any session presents.
 driver.navigate().to("url");
 2)back():it navigates to previous page
 driver.navigate().back();
 3)forward():it navigates to next page
 driver.navigate().forward();
 4)refresh():it refreshes the current page
 driver.navigate().refresh();
 =====================================================================
 Difference between get("url") and navigate().to("url"):

1)get("url") method does not allow driver to access the browser’s history while navigate() allows the driver to access the browser’s history 
and to navigate to a given URL.
2)You can not navigate back and forward using get() while same can be achieved through navigate().
3)There is no specific method for refresh a web page in get() while navigate() provides a method named refresh(). 
Ques)It was interview question. How you will refresh a page using get() method.?
Ans:You can refresh a page using get() also by calling get() method once again

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.