当前位置: 首页 > 知识库问答 >
问题:

如何解决无法为../Selenium-Server-Standalone-3.141.59.jar驱动模块描述[重复]

沃博裕
2023-03-14

启动层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");
         }

    }

}

共有1个答案

麻华辉
2023-03-14

>

  • 我建议重新考虑使用Selenium Remote Control,因为它已经过时了,不再受支持,Selenium Java client当前的稳定版本是3.141.59,它提供的WebDriver API目前是W3C标准。
  • 一旦您实现了选项1摆脱那些thread.sleep()因为它是某种形式的性能反模式,请选择显式等待,查看如何使用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>
    

  •  类似资料: