package org.coderinfo.demo; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class ForwardAndBack { private static final String GOOGLEURL = "http://www.google.com.hk"; private static final String BAIDUURL = "http://www.baidu.com"; public static void main(String[] args) throws InterruptedException { WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); //最大化浏览器界面 driver.get(GOOGLEURL); //访问谷哥的首页 ,此处放弃度娘。 Thread.sleep(2000); //Wait for page load driver.navigate().to(BAIDUURL); //访问度娘的首页 ,此处放弃谷哥。 Thread.sleep(2000); //Wait for page load driver.navigate().back(); //使用API:back 反回谷哥首页 Thread.sleep(2000); //Wait for page load driver.navigate().forward(); //使用API:forward 再次前往度娘首页 Thread.sleep(5000); driver.quit(); //彻底退出WebDriver } } |