selenium webdriver 登录百度

public class BaiduTest {
  private WebDriver driver;
  private String baseUrl;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = ExplorerBase.IESetting();
    baseUrl = "http://www.baidu.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testLoginB() throws Exception {
    driver.get(baseUrl);
    driver.manage().window().maximize();
    Thread.sleep(500);
    driver.findElement(By.id("lb")).click();
    driver.findElement(By.id("TANGRAM__PSP_10__pass-pop-login-placeholder-normal")).click();
    driver.findElement(By.id("TANGRAM__PSP_10__userName")).sendKeys("username");
    driver.findElement(By.id("TANGRAM__PSP_10__password")).click();
    driver.findElement(By.id("TANGRAM__PSP_10__password")).sendKeys("password");
    driver.findElement(By.id("TANGRAM__PSP_10__submit")).click();
    assertEquals("x429791240", driver.findElement(By.id("s_username_top")).getText());
    MouseActions.moveToElement(driver, By.id("s_username_top"));
    driver.findElement(By.linkText("退出")).click();
  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

 

posted @ 2013-08-24 17:04  苦逼IT男  阅读(1597)  评论(0编辑  收藏  举报