This example will show how the back and forward button works in selenium webdriver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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 { 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