[英]problem in executing selenium standalone jar
Hi I am beginner in Java selenium, i have problem in executing selenium standalone jar I am using eclipse version 4.15, JDk 14.0, selenium 3.14
錯誤在啟動層 java.lang.module.FindException 初始化期間發生錯誤:無法為 C 派生模塊描述符:\Java-selenium\selenium-server-standalone-3.141.59.9289954DBF044A
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
}
}
如果您要導入 JAR package,則包含.jar
文件的文件夾必須包含在項目的CLASSPATH中。 在此線程中,您可以找到在 Eclipse 中設置項目類路徑的說明。
您還應該考慮使用 package 管理器來管理依賴項,例如Maven 。 Eclipse 對 Maven 提供了很好的支持,您可以在這里找到詳細信息。 它是 Ubuntu 教程,而您可能正在使用 Windows,但這里重要的一切都是一樣的。
如果您還有其他問題,請評論此答案,我會相應地對其進行編輯。
如果您想嘗試 Maven,我附上了pom.xml
文件的示例 - Maven 項目的配置文件 - 我用於運行測試的 Selenuim 項目。 要使用此設置運行測試,您需要 go 到包含pom.xml
文件的文件夾。 在此文件夾中運行命令mvn clean test
在使用該文件之前,請替換或刪除:
com.example.your.domain
作為 groupIdyour-app-name
作為 artifactId,<repositories>
部分(因為我使用私人倉庫做一些事情)1.8
並且 Selenium 由 TestNG 框架管理,該框架由Surefire 插件執行,您不需要此設置,<?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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.