Browser back-forward button with selenium

selenium

This example will show how the back and forward button works in selenium webdriver

package com.webdriver_02;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class BrowserBackForword {

	public WebDriver driver;
	private String baseUrl;
	
	public static void main(String[] args) {
		BrowserBackForword bbf = new BrowserBackForword();
		bbf.launch_browser();
	}
	public void launch_browser() {
		try{
		baseUrl = "http://en.wikipedia.org/wiki/Selenium_%28software%29";
		driver = new FirefoxDriver();
		driver.get(baseUrl); 
		driver.manage().window().maximize();
		System.out.println("1.Present title - " + driver.getTitle());
		driver.findElement(By.xpath(".//*[@id='mw-content-text']/p[5]/a[1]")).click();
		System.out.println("2.Present title - " + driver.getTitle());
		Thread.sleep(2000);   
		driver.navigate().back();
		System.out.println("3.Present title - " + driver.getTitle());
		Thread.sleep(2000);  
		driver.navigate().forward();
		System.out.println("4.Present title - " + driver.getTitle());
		driver.quit();
		}
		catch (Exception ex)
		{
			ex.getMessage();
		}
	}
}

and the output should be –

1.Present title – Selenium (software) – Wikipedia, the free encyclopedia
2.Present title – Integrated development environment – Wikipedia, the free encyclopedia
3.Present title – Selenium (software) – Wikipedia, the free encyclopedia
4.Present title – Integrated development environment – Wikipedia, the free encyclopedia

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *