public class Test2
{
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception
{
driver = new FirefoxDriver();
baseUrl = "http://www.oschina.net/";
driver.manage().timeouts().implicitlyWait(30,
TimeUnit.SECONDS);
}
@Test
public void test2() throws Exception
{
driver.get(baseUrl + "/");
driver.findElement(By.id("channel_q" )).clear();
driver.findElement(By.id("channel_q" )).sendKeys("scala" );
driver.findElement(By.cssSelector("button.BTN" )).click();
driver.findElement(By.linkText("编程语言
Scala" )).click();
}
@After
public void tearDown() throws Exception
{
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString))
{
fail(verificationErrorString);
}
}
private boolean isElementPresent(By
by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException
e) {
return false;
}
}
private boolean isAlertPresent() {
try {
driver.switchTo().alert();
return true;
} catch (NoAlertPresentException
e) {
return false;
}
}
private String closeAlertAndGetItsText() {
try {
Alert alert = driver.switchTo().alert();
String alertText = alert.getText();
if (acceptNextAlert)
{
alert.accept();
} else {
alert.dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}