SUBSCRIBE HERE TO GET POST UPDATES VIA EMAIL :

Delivered by FeedBurner

Use of navigate() method in Selenium WebDriver

navigate() method is very frequently used method in selenium webdriver. Using this method, driver can navigate back, forward, refresh browser and navigate to specific URL. navigate() is very simple method and we can use it verify quickly in our selenium webdriver tests. Lets see how we can use navigate() method in selenium webdriver.

How to use navigate() method?
package TestPack;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class testnavigate {

 public static void main(String[] args) {
  String exePath = "D:\\chromedriver_win32\\chromedriver.exe";
  System.setProperty("webdriver.chrome.driver", exePath);
  WebDriver driver = new ChromeDriver();
  driver.manage().window().maximize();
  
  //Navigate to Given URL
  driver.navigate().to("http://only-testing-blog.blogspot.com/2014/01/new-testing.html");
  
  //Click on Link on page to redirect on other URL
  driver.findElement(By.xpath("//a[contains(text(),'Click Here')]")).click();
  
  //Navigate back to previous URL. Same as click Back button in browser.
  driver.navigate().back();
  
  //Navigate forward to Next URL. Same as click Forward button in browser.
  driver.navigate().forward();
  
  //Refresh page. Same as F5 in browser
   driver.navigate().refresh();
 }
}

Do you know how to use switchTo() with iFrames?

When to use navigate() method?
You can use navigate() method to navigate on given URL, Go Back, Go Forward browser button actions, and refresh browser tab.

No comments:

Post a comment