一、代码如下
package www.gui.huohu.pom;import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;public class DengLuPage {WebDriver driver;public static void main(String[] args) {// TODO Auto-generated method stubDengLuPage dl= new DengLuPage();dl.init();dl.doLogin("admin", "admin", true);}private void init() {// TODO Auto-generated method stubSystem.setProperty("webdriver.firefox.bin", "D:\\FireFox__37\\firefox.exe");this.driver = new FirefoxDriver();// 启动火狐浏览器this.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);// 元素等待时间this.driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);// 页面加载时间this.driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);// ajax请求this.driver.manage().window().maximize();// this.driver.get("https://www.baidu.com/");// 在浏览器中打开该网址this.driver.get("http://localhost/Agileone/");}private WebElement getUsernameInputbox() {// TODO Auto-generated method stubreturn this.driver.findElement(By.id("username"));}private WebElement getPasswordInputbox() {// TODO Auto-generated method stubreturn this.driver.findElement(By.id("password"));}private WebElement getSaveloginInputbox() {// TODO Auto-generated method stubreturn this.driver.findElement(By.id("savelogin"));}private WebElement getLoginButton() {// TODO Auto-generated method stubreturn this.driver.findElement(By.id("login"));}private void doLogin(String username, String password, Boolean isSaveLogin) {// TODO Auto-generated method stubthis.getUsernameInputbox().sendKeys(username);this.getPasswordInputbox().sendKeys(password);if(isSaveLogin){this.getSaveloginInputbox().click();}this.getLoginButton().click();}
}