无法通过 Selenium 3.4.0 启动 HtmlUnitdriver [英] Unable to launch HtmlUnitdriver through Selenium 3.4.0

查看:34
本文介绍了无法通过 Selenium 3.4.0 启动 HtmlUnitdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am tried to run the HtmlUnitDriver with selenium 3.4 and chrome Version 64.0.3282.119 (Official Build) (32-bit). My code is:

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

    }
    }

推荐答案

要使用 Selenium v​​3.4.0 调用 HtmlUnitDriver,您不需要 ChromeDriverem> 或 Chrome 浏览器客户端 您可以按照以下解决方案使用 org.openqa.selenium.htmlunit.HtmlUnitDriver 模块:

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
    

  • 注意:确保 HtmlUnitDriver() 不是从 :

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

    com.gargoylesoftware.htmlunit.BrowserVersion;
    

    这篇关于无法通过 Selenium 3.4.0 启动 HtmlUnitdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆