简体   繁体   English

使用 selenium web 驱动程序运行测试 - NoClassDefFoundError

[英]run test with selenium web driver - NoClassDefFoundError

I tried to figure out how works - selenium web driver.我试图弄清楚如何工作 - selenium web 驱动程序。

And tried to run easy program, but caught next error at console:并尝试运行简单的程序,但在控制台发现下一个错误:

java.lang.NoClassDefFoundError: selenium/web/driver/Selenium2Example
Caused by: java.lang.ClassNotFoundException: selenium.web.driver.Selenium2Example
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" 

and pop-up window with message:和带有消息的弹出窗口:

Could not find the main class, program will exit

I'm using Eclipse Helios under Windows XP.我在 Windows XP 下使用 Eclipse Helios。
I attached neded -jars for progect ( selenium-java-2.35.0 + selenium-server-standalone-2.35.0 ).我为 progect 附加了 neded -jars( selenium-java-2.35.0 + selenium-server-standalone-2.35.0 )。

Here is code:这是代码:

public class Selenium2Example {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface,
        // not the implementation.
        WebDriver driver = new FirefoxDriver();
        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Alternatively the same thing can be done like this
        // driver.navigate().to("http://www.google.com");
        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));
        // Enter something to search for
        element.sendKeys("Cheese!");
        // Now submit the form. WebDriver will find the form for us from the
        // element
        element.submit();
        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });
        // Should see: "cheese! - Google Search"
        System.out.println("Page title is: " + driver.getTitle());
        // Close the browser
        driver.quit();
    }

}

I can't understand why this couldn't find main class...我不明白为什么这找不到主类...

Even more it couldn't create executable files .class into bin folder.更重要的是它无法将可执行文件.class创建到bin文件夹中。

Any suggestion?有什么建议吗?

  • Why this exactly happen and how to solve this trouble?为什么会发生这种情况以及如何解决这个麻烦?

删除 selenium 独立 jar 并将selenium-java-2.33.0-srcs.jarselenium-java-2.33.0.jar 添加到 lib 并作为java 应用程序运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用硒网络驱动程序获取NoClassDefFoundError - getting NoClassDefFoundError using selenium web driver 使用Web驱动程序运行硒测试时,IE根本无法打开 - IE does not open up at all when I run selenium test using web driver Selenium Web驱动程序 - 如何在后台运行Firefox - Selenium Web Driver - How to run Firefox in the Background selenium web driver java.lang.NoClassDefFoundError:com / google / gson / JsonSyntaxException - selenium web driver java.lang.NoClassDefFoundError: com/google/gson/JsonSyntaxException 在一台机器上并行执行多个Selenium Web驱动程序测试用例 - Executing multiple Selenium Web driver test cases in parallel on one machine 无法在@Test Junit Selenium Web驱动程序中使用定位器 - Unable to use locators in @Test Junit Selenium web driver 如何在同一个硒网络驱动程序中跳过测试 - how can skip a test in same class- selenium web driver Edge 浏览器中的 Selenium Web 驱动程序测试抛出空指针异常 - Selenium web driver test in Edge browser throws null pointer exception 如果测试用例失败,Selenium Web驱动程序无法关闭firefox实例 - Selenium web driver not able to close firefox instance if a Test cases is failed 无法通过Selenium Web驱动程序在Firefox中运行我的程序 - Not able to run my program in Firefox through selenium web driver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM