Pages

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"):


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.