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;

public class testnavigate {

 public static void main(String[] args) {
  String exePath = "D:\\chromedriver_win32\\chromedriver.exe";
  System.setProperty("", exePath);
  WebDriver driver = new ChromeDriver();
  //Navigate to Given URL
  //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.
  //Navigate forward to Next URL. Same as click Forward button in browser.
  //Refresh page. Same as F5 in browser

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