Unable to launch HtmlUnitdriver through Selenium 3.4.0

假如想象 提交于 2019-11-29 18:49:27

Use this code to Initialize headless browser :

HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME ,true);
driver.get("your web URL");  

To invoke HtmlUnitDriver with Selenium v3.4.0 you don't need ChromeDriver or Chrome Browser Client instead you can use the org.openqa.selenium.htmlunit.HtmlUnitDriver module following the solution below :

  • Code Block :

    package HtmlUnitDriver;
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.htmlunit.HtmlUnitDriver;
    
    public class htmlUnitDriver {
    
        public static void main(String[] args) {
    
    
            WebDriver driver = new HtmlUnitDriver();
            driver.manage().window().maximize();
            driver.get("https://www.facebook.com/");
            System.out.println("Invoking Facebook through HtmlUnitDriver");
            System.out.println(driver.getTitle());
        }
    }
    
  • Console Output :

    Invoking Facebook through HtmlUnitDriver
    Facebook – log in or sign up
    

Note : Ensure that HtmlUnitDriver() is not resolved from :

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