简体   繁体   English

Selenium java.lang.NoSuchMethodError启动驱动程序

[英]Selenium java.lang.NoSuchMethodError in starting the driver

I have tried the code below to open a chrome webdriver and then open google.com using it: 我已经尝试过以下代码来打开chrome网络驱动程序,然后使用它打开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/");
 }

} 

But it complains in the line: 但它抱怨:

driver=new ChromeDriver();

with the following errors: 出现以下错误:

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)

And here is the complete dependencies: 这是完整的依赖项:

<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>

I am wondering, what is wrong with my code? 我想知道,我的代码有什么问题?

See last line of Exception at com.example.demo.Hook.testInitializer(Hook.java:20) , it is run time exception this is because your class is missing main method. 请参阅at com.example.demo.Hook.testInitializer(Hook.java:20)上的Exception的最后一行,它是运行时异常,这是因为您的类缺少main方法。

Quoting Java Language Specification (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 . 引用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 More specifically, it is looking for a method that should be declared as ... 更具体地说,它正在寻找一种应声明为...的方法。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Chrome驱动程序java.lang.NoSuchMethodError运行Selenium时出错: - Error when running Selenium with Chrome Driver java.lang.NoSuchMethodError: TestContainer 运行 Selenium Chrome 驱动程序,java.lang.NoSuchMethodError - TestContainer running a Selenium Chrome Driver, java.lang.NoSuchMethodError TestNG Selenium ChromeDriver:java.lang.NoSuchMethodError - TestNG Selenium ChromeDriver : java.lang.NoSuchMethodError Selenium Phantomjs 驱动程序 - java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; - Selenium Phantomjs driver - java.lang.NoSuchMethodError: org.openqa.selenium.os.CommandLine.find(Ljava/lang/String;)Ljava/lang/String; Selenium WebDriverWait(driver,Duration.ofSeconds(10)) 启动; java.lang.NoSuchMethodError - Selenium WebDriverWait(driver,Duration.ofSeconds(10)) launches; java.lang.NoSuchMethodError java.lang.NoSuchMethodError: - java.lang.NoSuchMethodError: java.lang.NoSuchMethodError - java.lang.NoSuchMethodError MonetDB COPY INTO java.lang.NoSuchMethodError 与新的 JDBC 3.0 驱动程序 - MonetDB COPY INTO java.lang.NoSuchMethodError with new JDBC 3.0 driver 将 DesiredCapabilities 与 Selenium Webdriver 中的 FirefoxOptions 合并导致 java.lang.NoSuchMethodError - Merging DesiredCapabilities with FirefoxOptions in Selenium Webdriver Results in java.lang.NoSuchMethodError Selenium网格,线程“ main”中的异常java.lang.NoSuchMethodError - Selenium grid, Exception in thread “main” java.lang.NoSuchMethodError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM