繁体   English   中英

我的 Java 代码仅在从 IDE 运行时才有效,而不是终端

[英]My Java code only works when ran from IDE, not terminal

我可以在 IDE 中正常运行我的 Java 程序,但是当我在命令行中尝试这第一步时:

  1. javac Main.java Test.java然后我得到一系列错误。

错误是说我所有的进口都不存在

Main.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                          ^
Main.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.Platform;
                          ^
Main.java:5: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
                          ^
Main.java:6: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebElement;
                          ^
Main.java:7: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.DesiredCapabilities;
                                 ^
Main.java:8: error: package org.openqa.selenium.remote does not exist
import org.openqa.selenium.remote.RemoteWebDriver;
                                 ^
Main.java:16: error: cannot find symbol
        DesiredCapabilities caps = new DesiredCapabilities();
        ^
  symbol:   class DesiredCapabilities
  location: class Main
Main.java:16: error: cannot find symbol
        DesiredCapabilities caps = new DesiredCapabilities();
                                       ^
  symbol:   class DesiredCapabilities
  location: class Main
Main.java:25: error: cannot find symbol
        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
        ^
  symbol:   class WebDriver
  location: class Main
Main.java:25: error: cannot find symbol
        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
                               ^
  symbol:   class RemoteWebDriver
  location: class Main
Main.java:27: error: cannot find symbol
        WebElement element = driver.findElement(By.name("q"));
        ^
  symbol:   class WebElement
  location: class Main
Main.java:27: error: cannot find symbol
        WebElement element = driver.findElement(By.name("q"));
                                                ^
  symbol:   variable By
  location: class Main
12 errors

我究竟做错了什么? 如何让我的代码正确找到这些导入?

编辑:我已经查看了其他答案,但它们对我不起作用。 我所有的 jar 文件都位于此处C:\Users\NROLL97\Documents\jars 这是我尝试过的示例:

javac -cp "C:\Users\NROLL97\Documents\jars\*.jar:." Main.java

对于可能遇到此问题的其他任何人...需要这样的东西: java -cp ".\target\classes;lib\*;" org.testng.TestNG ParallelTestXML.xml java -cp ".\target\classes;lib\*;" org.testng.TestNG ParallelTestXML.xml

.\target\classes是 class 文件(不是 .java 文件)的路径,而lib\*lib文件夹中我所有jars的路径。

现在将找到所有必要的依赖项

好的,我首先要向您推荐的是关于如何编译源代码,而不是编写您想要与任何其他 class 名称一起编译的每个 class 名称,只需使用 * 示例:javac *.Z93F725A07423B333FE1C886Z48 输入按钮)

此命令将一次编译所有 java 源文件,而不是单独编写它们的名称

Okay lets come to your problem Your compiler can't find selenium package or say.jar file which contains all the classes which are related to selenium classes

Download the.jar file which contains selenium related class in it and save it in the same location where you have saved your main.java and Test.java file

然后尝试编译它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM