gpt4 book ai didi

java - 在 Selenium 中使用 PhantomJS 时出错 : NoSuchMethodError org/openqa/selenium/browserlaunchers/Proxies

转载 作者:太空宇宙 更新时间:2023-11-04 10:52:20 27 4
gpt4 key购买 nike

我正在尝试使用 PhantomJS 运行非常简单的 Java 自动化测试用例。我正在使用以下版本:

  1. selenium-server-standalone3.8.1.jar
  2. 适用于 Windows 的 PhantomJS 2.1.1 版本
  3. PhantomJSdriver.jar 1.1。版本

我的代码所需的功能和驱动程序启动如下:

        DesiredCapabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"C:/Program Files/phantomjs-2.1.1-windows/bin/phantomjs.exe" //java web start / jnpl file...
// "/Controller/phantomjs.exe"
);

//SET enabled javascript for php script on WEB page to transform it to picture:
caps.setJavascriptEnabled(true);
String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);

//CREATING WEB driver
WebDriver driver = new PhantomJSDriver(caps);

但是,我收到此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:99) at HD_PhantomJSTest1.main(HD_PhantomJSTest1.java:33) Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 3 more

最佳答案

java.lang.NoClassDefFoundError

java.lang.NoClassDefFoundError 当 Java 虚拟机无法在运行时找到编译时可用的特定类时,会出现此错误。

举个例子,如果我们有一个来自类的方法调用或访问类的任何静态成员,并且该类在运行时不可用,那么 JVM 将抛出 java.lang.NoClassDefFoundError

根据您的测试床信息,我不确定是否包含PhantomJSdriver.jar 1.1。版本PhantomJS 的当前实现不需要任何额外的 jar。相关的 Selenium JAR 解决所需的依赖关系。因此您可以删除PhantomJSdriver.jar 1.1。版本

除此之外,我在您的代码中没有看到任何此类错误。然而,经过一些代码格式化后,我使用我的配置执行了您的代码,并且成功如下:

@Test
public void verifyFacebookTitle()
{
DesiredCapabilities caps = new DesiredCapabilities();
((DesiredCapabilities) caps).setJavascriptEnabled(true);
((DesiredCapabilities) caps).setCapability("takesScreenshot", true);
((DesiredCapabilities) caps).setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Utility\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe");
caps.setJavascriptEnabled(true);
String [] phantomJsArgs = {"--web-security=no", "--ignore-ssl-errors=yes"};
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomJsArgs);
WebDriver driver = new PhantomJSDriver(caps);
driver.get("https://www.facebook.com/");
System.out.println(driver.getTitle());
driver.quit();
}

我的控制台上的输出:

INFO: Detected dialect: OSS
Facebook – log in or sign up
[INFO - 2017-12-06T08:24:22.972Z] ShutdownReqHand - _handle - About to shutdown
PASSED: verifyFacebookTitle

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

关于java - 在 Selenium 中使用 PhantomJS 时出错 : NoSuchMethodError org/openqa/selenium/browserlaunchers/Proxies,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47665527/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com