import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Test {
public static void main(String[] args){
//創建壹個WebDriver實例
System.setProperty("webdriver.ie.driver", "Driver\\IEDriverServer.exe");
WebDriver driver= new InternetExplorerDriver();
//訪問百度
driver.get("www.baidu.com");
//另壹種方式
driver.navigate().to("www.google.com");
//找到文本框
WebElement element = driver.findElement(By.name("q"));
//搜索關鍵字
element.sendKeys("selenium");
//提交表單 webDriver會自動從表單中查找提交按鈕並提交
element.submit();
//檢查頁面title
System.out.println("頁面Title:"+driver.getTitle());
//設置等待時間為10秒
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
// TODO Auto-generated method stub
return d.getTitle().toLowerCase().startsWith("selenium");
}
});
// 顯示查詢結果title
System.out.println("Page title is: " + driver.getTitle());
//關閉瀏覽器
driver.quit();
}
}