代码之家  ›  专栏  ›  技术社区  ›  uingtea

无需IDE的Java硒运行命令提示CMD窗口

  •  0
  • uingtea  · 技术社区  · 6 年前

    我使用的是windows,但我没有安装eclipse ide或其他工具的权限,所以唯一的方法是通过命令提示符运行selenium,我知道有类似的问题 this this this 但这并没有解决我的问题。这是我的剧本

    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();
      }
    }
    

    当我在命令中运行following时

    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,所以我需要什么命令才能正确运行它?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Neha    6 年前
    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。

        2
  •  0
  •   undetected Selenium    6 年前

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

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