Use of navigate() method in Selenium WebDriver

navigate() method in selenium is very frequently used method. Using selenium navigate to url 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.

Navigation command in selenium

When you want to navigate specific URL in between your test then you can use Selenium navigate to url. Syntax for navigate to url in selenium is driver.navigate().to("Your URL");.

Other usages of navigate method in selenium

Also you can navigate back in selenium. Syntax for selenium go back to previous page is driver.navigate().back();. selenium navigate back to previous page using this syntax. Also you can navigate forward in selenium using driver.navigate().forward(); syntax.

Selenium refresh page

You can refresh page in selenium using navigate method as well. selenium webdriver refresh page can be done using driver.navigate().refresh();. It will refresh page in selenium test.

How to use navigate() to url in selenium?

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 in selenium
  //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 using selenium navigate

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

When to use selenium 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