java - 如何解决无法驱动../selenium-server-standalone-3.141.59.jar 的模块描述
问题描述
启动层 java.lang.module.FindException 初始化期间发生错误:无法为 C:\Users\admin\eclipse-workspace\Testing\lib\selenium-server-standalone.jar 派生模块描述符
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.eclipse.jetty.http.Http1FieldPreEncoder not in module
package Testing;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class Testing {
public static void main(String[] args) throws InterruptedException
{
Selenium selenium= new DefaultSelenium("localhost",4444,"firefox","http://www.calculator.net");
selenium.start();
selenium.open("/");
selenium.windowMaximize();
selenium.click("xpath=.//*[@id=''hl3']/li[3]/a");
Thread.sleep(4000);
selenium.focus("id=cpar1");
selenium.type("css=input[id=\"cpar1\"]", "10");
selenium.focus("id=cpar2");
selenium.type("css=input[id=\"cpar2\"]", "50");
(selenium).click("xpath=.//*[@id='content']/table[1]/tbody/tr[2]/td/input[2]");
// verify if the result is 5
Thread.sleep(4000);
String result = selenium.getText("xpath=.//*[@id='content']/p[2]/font/b");
//String result = selenium.getValue("xpath=.//*[@id='cpar3']");
System.out.println("Result:"+result);
if (result.equals("5")/*== "5"*/){
System.out.println("Pass");
}
else{
System.out.println("Fail");
}
}
}
解决方案
- 我建议重新考虑使用Selenium 远程控制,因为它已经过时,不再受支持,Selenium Java 客户端的当前稳定版本是3.141.59,它提供了WebDriver API,这是W3C 标准。
一旦你实现了选项 1 摆脱那些Thread.sleep(),因为它是某种形式的性能反模式,转而使用Explicit Wait,查看如何使用 Selenium 使用 AJAX 技术测试 Web 应用程序以获得全面的解释和代码例子。
最好使用像Apache Maven这样的依赖管理解决方案,它会自动检测并下载您的项目传递依赖项。相关的 pom.xml 文件类似于:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>selenium</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>8</source> <target>8</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> </dependencies> </project>
推荐阅读
- splunk - 有没有办法在计数层中按字典顺序对 top 命令的输出进行排序
- r - Rstudio代码使用断点和ctrl-Enter乱序执行?
- excel - Dynamically add a formula with my Excel userform everytime I hit submit
- php - AWS Lightsail 上的错误“检测到捆绑包的循环依赖项”,在 XAMP 中工作正常
- assembly - 如何管理 JMP CALL POP 例程中的结构?
- javascript - 如何在时钟应用程序中用当前时间自动替换过去的秒/分钟/小时
- python - 从一个大字符串中提取参数值
- javascript - 如何将给定表的整数列显示为从 1 开始到前端用户的自动递增系列?
- python - 从基于类的视图中访问请求对象?需要确定请求是否来自移动设备
- sql-server - SQL Server - sp_rename 后的列无效