我使用selenium webdriver来自动化我的测试用例。
我的目标是在样本selenium脚本上使用HtmlUnitDriver
执行无头浏览器。请找到下面提到的脚本:
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.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Headless
{
public static void main(String[] args) throws InterruptedException
{
HtmlUnitDriver driver = new HtmlUnitDriver();
//driver.setJavascriptEnabled(true);
// WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.co.in/?gfe_rd=cr&ei=k36cVsa6OubI8Aec14bICQ&gws_rd=ssl");
/*WebDriverWait wait=new WebDriverWait(driver,120);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("sb_ifc0")));
*/
Thread.sleep(50000);
System.out.println("URL= "+driver.getCurrentUrl());
System.out.println("Page title is: " + driver.getTitle());
}
}
输出是:
URL= about:blank
Page title is:
输出适用于FirefoxDriver()
有人可以指导我哪里出错吗?