Headless browser not executing properly

荒凉一梦 提交于 2019-12-08 09:37:03

问题


I use selenium webdriver to automate my test-cases.

My objective to execute headless browser using HtmlUnitDriver on a sample selenium script. Please find the script mentioned below:

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());     
    }
}

And the output is:

URL= about:blank
Page title is: 

The output is working fine for FirefoxDriver()

Could anyone guide where I went wrong?

来源:https://stackoverflow.com/questions/34891035/headless-browser-not-executing-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!