navigate back and forward in the browser history

Browser Navigate Back and Forward in Selenium

Last updated on

During automation, we are at times required to move back to the previous page or move forward to the next page in browser history. In this post, we will learn to perform these operations using driver.navigate command.

Navigate back in Selenium


Navigate forward in Browser History


Sample code

public static void main(String[] args) throws InterruptedException{
	//Setting system property required for launching chrome browser
	System.setProperty("", "driverExecutables\\chromedriver.exe");
	//Launching chrome browser
	WebDriver driver = new ChromeDriver();
	//Navigating to the desired website
	//Used for demo purpose only, not required
	//Clicking a link
	WebElement artOfTestingLogo = driver.findElement(By.cssSelector("div.navbar-header"));;
	//Navigating back in browser 
	//Used for demo purpose only, not required
	//Navigating forward in browser 

That’s all we have in this post, comment below if you have any queries. Don’t forget to check our complete selenium tutorial here.

Selenium Webdriver with Java Tutorial

Leave a Comment