【问题标题】:Selenium error in simple java code简单Java代码中的Selenium错误
【发布时间】:2017-06-07 13:15:58
【问题描述】:

我正在学习 selenium,我只是从网站上复制了一个简单的 java 代码并尝试运行它。但它给了我以下错误。请帮我修复它。

安装的文件:

 1. Selenium api 2.44.0
 2. Selenium firefox driver 2.44.0
 3. Seleinium server stand alone 2.53.1
 4. Selenium support 2.44
 5. Firefox version - 35.1.0

错误:

线程“main”中的异常 java.lang.NoClassDefFoundError:
org/openqa/selenium/remote/internal/CircularOutputStream 在 org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:59) 在 org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:55) 在 org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:95) 在 Sel.OpenGoogle.main(OpenGoogle.java:6) 引起: java.lang.ClassNotFoundException: org.openqa.selenium.remote.internal.CircularOutputStream 在 java.net.URLClassLoader.findClass(未知来源)在 java.lang.ClassLoader.loadClass(Unknown Source) 在 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 4 更多

我的代码:

package Sel;
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.firefox.FirefoxDriver;  
public class OpenGoogle {  
  public static void main(String args[]){  
  WebDriver driver=new FirefoxDriver();  
  System.out.println("Hello Google...");  
  driver.get("http://google.com");    
    }  
 } 

添加 selenium 远程驱动程序 2.4.4 后出错

Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'PC', ip: '192.168.1.2', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_101'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:72)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:59)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:55)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at Sel.OpenGoogle.main(OpenGoogle.java:6)

【问题讨论】:

标签: java selenium firefox selenium-webdriver automated-tests


【解决方案1】:

@Stack Mark 从此链接下载 selenium 2.53 for java

http://selenium-release.storage.googleapis.com/index.html?path=2.53/

删除所有当前安装的 jar 文件并加载新的。注意不要删除 JRE 系统库。 然后一切都会正常工作。 顺便问一下你用的是哪个firefox浏览器?我正在使用 47.0.1 好处是您不必使用壁虎驱动程序。

【讨论】:

  • 当我按照您的步骤操作并使用 35.0.1 `Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function at Sel.OpenGoogle 时出现此错误。 main(OpenGoogle.java:7) 引起:java.lang.ClassNotFoundException: com.google.common.base.Function at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source)在 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 更多'
【解决方案2】:

OpenGoogle.java

您的代码在我的系统上运行良好。您最好检查 jdk 的类路径。 希望这可以帮助。 :) 除此之外检查这些。 http://www.codegravity.com/blog/exception-in-thread-main-java-lang-noclassdeffounderror

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-22
    • 2014-08-16
    • 2011-09-21
    • 2012-01-20
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    相关资源
    最近更新 更多