我寫了下面的代碼中使用硒驅動程序來調用谷歌瀏覽:org.testng.TestNGException:無法實例類
package automation_se;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class InvokeChrome {
public WebDriver driver;
public InvokeChrome() {
System.setProperty("webdriver.chrome.driver", "D:\\downloads\\chromedriver_win32\\chromedriver");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@Test
public void chromeProgram() {
}
}
在運行程序作爲爲TestNG的測試,它拋出以下異常:
org.testng.TestNGException:
Cannot instantiate class automation_se.InvokeChrome
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40)
at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:382)
at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:295)
at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:118)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:183)
at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:128)
at org.testng.TestRunner.initMethods(TestRunner.java:416)
at org.testng.TestRunner.init(TestRunner.java:242)
at org.testng.TestRunner.init(TestRunner.java:212)
at org.testng.TestRunner.<init>(TestRunner.java:166)
at org.testng.remote.support.RemoteTestNG6_9_7$1.newTestRunner(RemoteTestNG6_9_7.java:27)
at org.testng.remote.support.RemoteTestNG6_9_7$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_9_7.java:63)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:587)
at org.testng.SuiteRunner.init(SuiteRunner.java:161)
at org.testng.SuiteRunner.<init>(SuiteRunner.java:114)
at org.testng.TestNG.createSuiteRunner(TestNG.java:1290)
at org.testng.TestNG.createSuiteRunners(TestNG.java:1277)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1131)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29)
... 21 more
Caused by: java.lang.IllegalStateException: The driver executable does not exist: D:\downloads\chromedriver_win32\chromedriver
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at automation_se.InvokeChrome.<init>(InvokeChrome.java:17)
... 26 more
任何人都可以請這個例外幫助我嗎?將不勝感激。
我讀過類似的問題,但他們似乎都有程序特定的解決方案。
錯誤java.lang.IllegalStateException:驅動程序可執行文件不存在:D:\ downloads \ chromedriver_win32 \ chromedriver'說明了一切。提供'chromedriver.exe'而不是'chromedriver' – DebanjanB