【问题标题】:Error : java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices , when running tests using ghostdriver错误:java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices,使用 ghostdriver 运行测试时
【发布时间】:2013-09-16 10:35:49
【问题描述】:

我正在尝试使用 ghostdriver (Phantomjs) 运行我的 webdriver 测试用例,但这会给出错误 java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices
对我来说一切都很好,但我不明白为什么会出现错误。
操作系统 - WIN7
编码 - JAVA 1.7
框架:java1.7+testng6.5.2+maven3
Selenium-java 版本 2.35.0


测试用例

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

public class ghosttest {

    WebDriver driver;

    @Test
    public void testing() {

        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setJavascriptEnabled(true); 
        caps.setCapability(
        PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        "D:/dumps/phantomjs-1.9.1-windows/phantomjs-1.9.1-windows/phantomjs.exe");
        driver = new PhantomJSDriver(caps);
        driver.get("http://www.google.com");

        String Logintext = driver.findElement(By.linkText("Maps")).getText();
        System.out.println(Logintext);

    }
}


ghostdriver 的 Maven 依赖项

<dependency>
    <groupId>com.github.detro.ghostdriver</groupId>
    <artifactId>phantomjsdriver</artifactId>
    <version>1.0.3</version>
</dependency>

【问题讨论】:

    标签: webdriver maven-3 phantomjs


    【解决方案1】:

    你的问题是ghostdriver不是compatible with Selenium 2.35

    如果您将依赖项更改为 2.34,您会没事的。不幸的是,如果您特别需要 Selenium 2.35,您将不得不等待新的 PhantomJSDriver。

    目前phantomjsdriver的最新版本也是1.0.4,你有1.0.3。

    【讨论】:

    • 这话很刻薄,但我设法在您回答之前解决了它。但是问题仍未解决,因为我收到此错误“无法启动新会话。可能的原因是远程服务器的地址无效或浏览器启动失败。构建信息:版本:'2.34.0',修订:'11cd0ef93615408e0b6b3bfa28defe125906461a ',时间:'2013-08-06 11:43:14' 系统信息:os.name:'Linux',os.arch:'amd64',os.version:'3.5.0-21-generic',java .version: '1.7.0_25' 驱动信息: driver.version: PhantomJSDriver"
    • 我认为你的路径有问题。我正在使用 Linux,在我的情况下,我通过 nodejs 安装了 PhantomJS,使用npm -g install phantomjs。然后它就起作用了,我不需要指定任何二进制文件,但是节点当然将它添加到系统路径中。如果还没有,您可以尝试自己在 Windows PATH 中添加它。然后我会尝试删除功能配置并直接尝试驱动程序。我认为它确实自动支持 JavaScript。
    • 我想如果我这样做的话我会成功,即将节点添加到系统路径,但我不知道该怎么做。你能分享一段代码吗?
    • 对于没有使用GhostDriver但仍然面临同样问题的人请查看解决方案here
    猜你喜欢
    • 2020-04-28
    • 1970-01-01
    • 2016-08-10
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多