无法通过Selenium 3.4.0启动HtmlUnitdriver

无法通过Selenium 3.4.0启动HtmlUnitdriver,selenium,selenium-webdriver,webdriver,ghostdriver,htmlunit-driver,Selenium,Selenium Webdriver,Webdriver,Ghostdriver,Htmlunit Driver,我尝试使用selenium 3.4和chrome版本64.0.3282.119(官方版本)(32位)运行HtmlUnitDriver。 我的代码是: package eclipse; import java.io.File; import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.UnexpectedAlertBehaviour; import org

我尝试使用selenium 3.4和chrome版本64.0.3282.119(官方版本)(32位)运行HtmlUnitDriver。 我的代码是:

package eclipse;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;  
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.gargoylesoftware.htmlunit.BrowserVersion;

public class Unit
{
    WebDriver driver;
    public static void main(String[] args){
        WebDriver driver;
        driver = new HtmlUnitDriver(BrowserVersion.CHROME);
        driver.get("http://www.google.com");
        System.out.println(driver.getTitle());

    }
    }

使用以下代码初始化无头浏览器:

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

要使用Selenium v3.4.0调用HtmlUnitDriver,您不需要ChromeDriver或Chrome浏览器客户端,您可以按照以下解决方案使用
org.openqa.Selenium.htmlunit.HtmlUnitDriver
模块:

  • 代码块:

    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());
        }
    }
    
  • 控制台输出:

    Invoking Facebook through HtmlUnitDriver
    Facebook – log in or sign up
    
注意:确保
HtmlUnitDriver()
未从以下位置解析:

com.gargoylesoftware.htmlunit.BrowserVersion;

我尝试过这样做:但输出是-log4j:WARN无法找到记录器(com.gargoylesoftware.htmlunit.WebClient)的附加器。log4j:警告请正确初始化log4j系统。通过HtmlUnitDriver调用Facebook能否告诉我HtmlUnitDriver兼容的版本?@Naveen此代码块将在Selenium v3.4.0和最新的Selenium v3.12.0上运行。只需复制粘贴代码并更改包名我使用的是v3.4.0。。。我已经尝试简单地复制和粘贴代码,但是页面标题不适合我?@Naveen这些警告消息log4j:WARN无法为logger(com.gargoylesoftware.htmlunit.WebClient)找到任何附加程序。log4j:警告请正确初始化log4j系统。由于您尚未为此项目配置
Log4j
模块,因此将出现。否则,通过HtmlUnitDriver调用Facebook,您将获得如下正确的控制台输出,我认为您的程序执行得非常完美:)