无法通过Selenium 3.4.0启动HtmlUnitdriver

编程入门 行业动态 更新时间:2024-10-28 19:22:31
本文介绍了无法通过Selenium 3.4.0启动HtmlUnitdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试使用硒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("www.google"); System.out.println(driver.getTitle()); } }

推荐答案

要使用 Selenium v​​3.4.0 调用 HtmlUnitDriver ,您不需要 ChromeDriver 或 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("www.facebook/"); 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

    本文发布于:2023-11-04 11:30:36,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1557809.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Selenium   HtmlUnitdriver

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!