一、代码如下
package www.woniu.dibanben;
import java.awt.List;
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;
public class ChaoLianJieWenBenPart__V1 {
WebDriver driver;
public static void main(String[] args) {
// TODO Auto-generated method stub
ChaoLianJieWenBenPart__V1 dv= new ChaoLianJieWenBenPart__V1();
dv.init();
dv.doLogin();
}
private void init() {
// TODO Auto-generated method stub
//System.setProperty("webdriver.firefox.bin", "D:\Mozilla Firefox_53\firefox.exe");
System.setProperty("webdriver.firefox.bin", "D:\mozilla 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.get("http://localhost/Agileone/index.php");//在浏览器中打开该网址
}
private void doLogin() {
// TODO Auto-generated method stub
java.util.List<WebElement> elements= this.driver.findElements(By.tagName("input"));
elements.get(0).sendKeys("admin");
elements.get(2).sendKeys("admin");
this.driver.findElement(By.cssSelector("input.loginbt")).click();
this.driver.findElement(By.linkText("※ 测试用例 ※")).click();
}
}