Selenium java.lang.nosuchmethoderror启动驾驶员



我尝试了以下代码打开Chrome webdriver,然后使用它打开Google.com:

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
 public class Hook{
  private WebDriver driver;
  public void testInitializer(){
    File file = new 
        File(Application.class.getClassLoader()
                .getResource("driver/chromedriver.exe").getFile());
    String driverPath=file.getAbsolutePath();
    System.out.println("Webdriver is in path: "+driverPath);
    System.setProperty("webdriver.chrome.driver",driverPath);
    driver=new ChromeDriver();
}
 public Hook() {
     testInitializer();
     driver.get("https://www.google.com/");
 }
} 

,但它在行中抱怨:

driver=new ChromeDriver();

带有以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create(Ljava/util/concurrent/ExecutorService;)Lcom/google/common/util/concurrent/SimpleTimeLimiter;
    at org.openqa.selenium.net.UrlChecker.<init>(UrlChecker.java:62)
    at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
    at org.openqa.selenium.remote.RemoteWebDriver.execute
    at org.openqa.selenium.remote.RemoteWebDriver.startSession
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
    at org.openqa.selenium.chrome.ChromeDriver.<init>
    at org.openqa.selenium.chrome.ChromeDriver.<init>
    at org.openqa.selenium.chrome.ChromeDriver.<init>
    at com.example.demo.Hook.testInitializer(Hook.java:20)

这是完整的依赖性:

<dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.4.0</version>
            </dependency>
            <dependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-java</artifactId>
                <version>1.2.5</version>
            </dependency>

我想知道,我的代码怎么了?

请参见异常的最后一行at com.example.demo.Hook.testInitializer(Hook.java:20),这是运行时间异常,这是因为您的类缺少main方法。

引用Java语言规范(JLS(A Java virtual machine starts execution by invoking the method main of some specified class, passing it a single argument, which is an array of strings。更具体地说,它正在寻找应将其声明为...

的方法
public class Hook {
    ...
    public static void main(String[] args) {
        // body of main method follows
        ...
    }
}

相关内容

  • 没有找到相关文章

最新更新