【问题标题】:problem in executing selenium standalone jar执行 selenium 独立 jar 的问题
【发布时间】:2020-07-26 14:29:33
【问题描述】:

嗨,我是 Java selenium 的初学者,我在执行我正在使用的 selenium 独立 jar 时遇到问题 eclipse 版本 4.15,JDK 14.0,selenium 3.14

出现错误 启动层初始化时出错 java.lang.module.FindException:无法为 C:\Java-selenium\selenium-server-standalone-3.141.59.jar 派生模块描述符

package SeleniumPractice;
import org.openqa.selenium.chrome.ChromeDriver;//error importing org.openqa.selenium.chrome.ChromeDriver not accessible

public class launchBrowser {

    public static void main(String[] args) {
        //launch chrome browser
        System.setProperty("webdriver.chrome.driver", "./driver/chromedriver.exe");
        ChromeDriver driver = new ChromeDriver();//Error: cannot b resolved
    }

}

【问题讨论】:

    标签: java selenium-chromedriver


    【解决方案1】:

    如果您要导入 JAR 包,则包含 .jar 文件的文件夹必须包含在项目的 CLASSPATH 中。 In this thread 你可以找到在 Eclipse 中设置项目类路径的说明。

    您还应该考虑使用包管理器来管理依赖项,例如Maven。 Eclipse 对 Maven 提供了很好的支持,你可以找到详细信息here。这是 Ubuntu 教程,而您可能正在使用 Windows,但这里的所有重要内容都是一样的。

    如果您还有其他问题,请评论此答案,我会相应地对其进行编辑。


    如果您想尝试 Maven,我附上了一个 pom.xml 文件的示例 - Maven 项目的配置文件 - 我用于运行 Selenuim 测试。要使用此设置运行测试,您需要转到包含 pom.xml 文件的文件夹。在此文件夹中运行命令mvn clean test

    在使用文件之前,替换或删除:

    • com.example.your.domain 作为 groupId
    • your-app-name 作为 artifactId,
    • <repositories> 部分(因为我在一些事情上使用了私人仓库)
    • 任何不适合您的东西 - 请注意 Java 版本设置为 1.8 并且 Selenium 由 TestNG 框架管理,该框架由 Surefire plugin 执行,您不需要此设置。
    <?xml version="1.0" encoding="UTF-8"?>
    <project
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
    >
    
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.example.your.domain</groupId>
        <artifactId>your-app-name</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.0.0-M5</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
                        <properties>
                            <property>
                                <name>reporter</name>
                                <value>listenReport.Reporter</value>
                            </property>
                        </properties>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    <!--    <repositories>
            <repository>
                You might have to add a custom repo.
            </repository>
        </repositories>-->
    
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.141.59</version>
            </dependency>
        </dependencies>
    </project>
    
    

    【讨论】:

      猜你喜欢
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多