問題描述
我正在運行以下但收到錯誤
I am running the following but getting the error
public class base
{
public static WebDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\code\lib\browser drivers\chromedriver.exe");
String URL = "http://www.google.com";
String Node = "http://localhost:4444/wd/hub";
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap = DesiredCapabilities.chrome();
cap.setPlatform(org.openqa.selenium.Platform.WINDOWS);
driver = new RemoteWebDriver(new URL(Node), cap);
driver.navigate().to(URL);
Thread.sleep(5000);
driver.quit();
}
}
錯誤顯示如下:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: ChromeDriverService
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'RAJESHW10', ip: '169.254.3.253', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
Driver info: driver.version: unknown
Command duration or timeout: 316 milliseconds
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
有人可以幫忙嗎
推薦答案
請執行以下操作并重試.
Please do the following and retry.
確保將路徑 C:\code\lib\browser drivers\chromedriver.exe
添加到計算機上的 %PATH%
變量中您正在運行的節點.這將確保 selenium uber jar 可以找到 chromedriver 二進制文件的位置.
Ensure that the path C:\code\lib\browser drivers\chromedriver.exe
is added to your %PATH%
variable on the machine in which you are running the node. This would ensure that the selenium uber jar can find the location of the chromedriver binary.
System.setProperty("webdriver.chrome.driver", "C:codelibrowser driverschromedriver.exe");
這個機制應該只在你做的時候使用
This mechanism should be only used when you are doing
ChromeDriver 驅動程序 = ChromeDriver()
由于您使用的是 selenium 網格,因此您在這里處理的是多個 JVM.
Since you are working with a selenium grid, you are dealing with multiple JVMs here.
System.setProperty()
只會影響當前的 JVM(在這種情況下是您的測試),但實際的瀏覽器會在不同的 JVM(運行 selenium 的那個節點).
System.setProperty()
will affect only the current JVM (which in this case is your tests), but the actual browser gets spun off in a different JVM (the one that is running the selenium node).
這篇關于運行 selenium 遠程驅動程序時出現帶有 NativeConstructorAccessorImpl.newInstance0 的錯誤 SessionNotCreatedException的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!