Monday, October 27, 2014


In my earlier posts, we have learned WebDriver's Drivers, WebDriver's Commands. In this tutorial, we will learn how to navigate on specific page or URL.

1. get(String URL) - This method will load a web page of given URL in the current browser.

Example: driver.get(“www.google.com”);


2. driver.navigate().to(String URL) - This method will load a web page of given URL in the current browser.

Example: driver.navigate().to("http://www.google.com");


Difference between get() and navigate()


Both navigate().to() and get() do exactly the same thing but with navigate we can go to the next page OR come back to the previous page OR refresh the current page.

1. driver.navigate().forward() - This command is used to go next page. Click here for example.

2. driver.navigate().back() - This command is used to go previous page. Click here for example.

3. driver.navigate().refresh() - This command is used to refresh the current page. Click here for example.







WebDriver Navigate() Example



import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class NavigateExample {

 public static void main(String[] args) {

  WebDriver driver = new FirefoxDriver();
  driver.navigate().to("http://www.google.com");
  WebElement element = driver.findElement(By.name("q"));
  element.sendKeys("Selenium");
  element.submit();

 }

}