我正在尝试使用ghostdriver(Phantomjs)运行我的webdriver测试用例但是这会给出错误java.lang.NoClassDefFoundError: org/openqa/selenium/HasInputDevices
。
对我来说一切似乎都很好,但我不明白为什么会有错误
OS - WIN7
编码 - JAVA 1.7
框架:java1.7 + testng6.5.2 + maven3
Selenium-java版本2.35.0
testcase
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>
答案 0 :(得分:8)
你的问题是ghostdriver不是compatible with Selenium 2.35。
如果您将依赖项更改为2.34,那么您将没事。如果你特别需要Selenium 2.35,你将不得不等待新的PhantomJSDriver。
目前最新版本的phantomjsdriver也是1.0.4,你有1.0.3。