![](/img/trans.png)
[英]Error when running Selenium with Chrome Driver java.lang.NoSuchMethodError:
[英]Selenium java.lang.NoSuchMethodError in starting the driver
我已經嘗試過以下代碼來打開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/");
}
}
但它抱怨:
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)
上的Exception的最后一行,它是運行時異常,這是因為您的類缺少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
...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.