HtmlUnitDriver
钱经业
2023-12-01
package demo;
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.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.reporters.EmailableReporter;
public class DemoUseHtmlUnitDriver {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin","D:\\firefox\\firefox.exe");
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.baidu.com");
// driver.navigate().to("http://www.google.com");
WebElement element = driver.findElement(By.id("kw"));
element.sendKeys("Selenium");
element.submit();
System.out.println("Page title is " + driver.getTitle());
new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("Selenium");
}
});
System.out.println("page title is :" + driver.getTitle());
driver.quit();
}
}