package baidu; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver.Navigation; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class selenium { public static void main (String [] args) throws InterruptedException { String URL="http://www.baidu.com"; System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get(URL); /* Navigation navigation = driver.navigate(); navigation.to(URL);*/ Thread.sleep(2000); // WebElement keyWord = driver.findElement(By.id("kw1")); WebElement keyWord = driver.findElement(By.xpath("//input[@id=‘kw1‘]")); keyWord.sendKeys("Selenium"); WebElement submit = driver.findElement(By.id("su1")); submit.click(); Thread.sleep(5000); System.out.println(driver.getTitle()); Thread.sleep(5000); // navigation.back(); Thread.sleep(15000); System.out.println(driver.getTitle()+"\n"+driver.getCurrentUrl()); // driver.quit(); } }
selenium webdriver学习(一),布布扣,bubuko.com
原文:http://www.cnblogs.com/tobecrazy/p/3585608.html