簡體   English   中英

Java Selenium在沒有IDE的情況下通過命令提示符CMD Windows運行

[英]Java Selenium Run through Command Prompt CMD Windows Without IDE

我正在使用Windows,但是我無權安裝Eclipse IDE或其他工具,因此唯一的方法是通過命令提示符運行selenium,我知道有類似的問題,例如thisthisthis,但這不能解決我的問題。 這是我的劇本

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因為在我的腳本中這是主目錄,那么正確運行它所需的命令是什么?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM