【发布时间】:2018-09-17 00:52:31
【问题描述】:
我正在关注本教程:https://www.youtube.com/watch?v=UlY_6N98WWs&list=PLIBI8eaaUGfSupVFlMBefGodvWQ9ydq51&index=4 并得到了这个错误:
$ java -classpath selenium-server-standalone-3.11.0.jar HelloWorld
Error: Could not find or load main class HelloWorld
但如果我运行$ java HelloWorld,它就可以正常工作,并说
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver at
HelloWorld.main(HelloWorld.java:13) Caused by:
java.lang.ClassNotFoundException:
org.openqa.selenium.firefox.FirefoxDriver at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.j
我在 Mac 终端上,我尝试使用 CLASSPATHs 或 . 和空白。我的 $PATH 变量是 /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin 并且似乎没问题。
我尝试查看这些页面的解决方案: https://docs.oracle.com/javase/tutorial/essential/environment/paths.html https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html What does "Could not find or load main class" mean?
我的课程路径似乎运行良好,但还有其他问题?
HelloWorld.java
/**
* Import FirefoxDriver and By from selenium jar
*/
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HelloWorld{
public static void main(String args[]) throws Exception{
// Create a Firefox browser instance
FirefoxDriver driver = new FirefoxDriver();
// Navigate to google home page
driver.get("https://www.google.co.in/");
// Type hello world in the search field
driver.findElement(By.name("q")).sendKeys("Hello World");
// Wait for 10 seconds
Thread.sleep(10*1000);
// Close the browser instance
driver.quit();
}
}
Selenium Standalone Server 3.11.0 版下载自: https://www.seleniumhq.org/download/
我在 Mac OS 10.13.3 上运行。
【问题讨论】:
-
试试这个:
java -classpath .:selenium-server-standalone-3.11.0.jar HelloWorld
标签: java selenium terminal javac