package com.second.test;
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.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LietouTest {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
由于firefox浏览器安装的不是默认目录,所以需要指定一下,或者设置环境变量也可以
WebDriver driver = new FirefoxDriver(); //初始化一个浏览器
// WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.lietou.com"); //打开猎聘网首页
WebElement username =driver.findElement(By.id("user_login"));//找到用户名登陆框
username.sendKeys("
[email protected]");//输入用户名
WebElement passwd =driver.findElement(By.id("user_pwd"));
passwd.sendKeys("1234567788");
WebElement login =driver.findElement(By.name("submit"));
login.submit();//提交刚输入的用户名和密码
System.out.println("Page title is: " + driver.getTitle());//打印出该页的title
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {//判断登陆后的页面是否以“我的首页”开头,并且设置超时时间为10秒钟,如果是就进行下步操作,如果不是就报异常
public Boolean apply(WebDriver d) {
return d.getTitle().startsWith("我的首页");
}
});
System.out.println("Page title is: " + driver.getTitle());
driver.quit();//退出测试
}
}