Java Selenium在没有IDE的情况下运行命令提示符CMD Windows



我使用的是Windows,但我没有安装Eclipse IDE或其他软件的权限,所以唯一的方法是通过命令提示符运行selenium,我知道也有类似的问题,但这并没有解决我的问题。这是我的脚本

mySelenium.java

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class mySelenium {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
// Open Google
driver.get("https://www.example.com");
// Close browser
driver.quit();
}
}

当我在CMD 中运行以下程序时

java -classpath "selenium-server-standalone-3.141.59.jar" mySelenium.java
java -classpath "selenium-server-standalone-3.141.59.jar" mySelenium

我得到错误

Error: Could not find or load main class mySelenium.java

我不明白为什么它找不到main,因为在我的脚本中这里是main,那么我需要什么命令才能正确运行它?

java -classpath "selenium-server-standalone-3.141.59.jar" mySelenium.java
java -classpath "selenium-server-standalone-3.141.59.jar" mySelenium

应该是:

**javac** -classpath "selenium-server-standalone-3.141.59.jar" mySelenium.java
java -classpath "selenium-server-standalone-3.141.59.jar" mySelenium

您编写的是java而不是javac。

您必须将当前目录添加到类路径中。

java -classpath "selenium-server-standalone-3.141.59.jar;." mySelenium

相关内容

最新更新