Selenium WebDriver Navigation Commands

Navigation Commands:

Given are some of the most used navigation commands.

1. Forward Command:

Command
driver.navigate().forward();  

This method enables the web browser to click on the forward button in the existing browser window. It neither accepts anything nor returns anything.

2. Back Command:

Command
driver.navigate().back();

this method enables the web browser to click on the back button in the existing browser window. It neither accepts anything nor returns anything.

3. Navigate To Command:

Command
driver.navigate().to("URL");  

This method loads a new web page in the existing browser window. It accepts String as parameter and returns void.

4. Refresh Command:

Command
driver.navigate().refresh();

this method refresh/reloads the current web page in the existing browser window. It neither accepts anything nor returns anything.

Example:

CODE
package pkg1;

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

public class Navigation_Commands {

	public static void main(String[] args) {

	//System Property for Chrome Driver 
        System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Files\\chromedriver.exe");
  
	//Instantiate a ChromeDriver class.
        WebDriver driver = new ChromeDriver();
  
        //Maximize the browser
        driver.manage().window().maximize();
  
        // Launch Website    
        driver.navigate().to("https://www.bookofnetwork.com/automation-testing/Automation-Testing-With-Selenium");     

        //Click on the Link Text using click() command    
        driver.findElement(By.xpath("//a[text()=`2. Navigation Commands`]")).click();  

        //Go back to Home Page  
        driver.navigate().back();   

        //Go forward to Registration page  
        driver.navigate().forward();  

        //Refresh browser  
        driver.navigate().refresh();  
    
        //Closing browser  
        driver.close();   
        
        
	}

}

#navigation_commands_in_selenium #Forward_navigation_ #Back_navigation_command #Navigate_To_Command #Refresh_Command_in_selenium #Navigation_commands_with_example

(New page will open, for Comment)

Not yet commented...