我试图弄清楚是如何工作的——硒网络驱动程序。
并试图运行简单的程序,但在控制台中发现了下一个错误:
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"
和带有消息的弹出窗口:
Could not find the main class, program will exit
我在 Windows XP 下使用 Eclipse Helios。
我为 progect ( selenium-java-2.35.0
+ selenium-server-standalone-2.35.0
) 附加了 neded -jars。
这是代码:
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();
}
}
我不明白为什么这找不到主课......
更甚的是,它无法将可执行文件创建.class
到bin
文件夹中。
有什么建议吗?
- 为什么会发生这种情况以及如何解决这个问题?