我想用Java编写Selenium Grid应用程序。
在http://localhost:4444/grid/console上,它指示该节点已连接到集线器。
在客户端,我想编写以下代码:
try {
DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://IP of Hub:4444/wd/hub"), capability);
capability.setBrowserName("firefox");
driver.get("https://www.google.com");
} catch (MalformedURLException ex) {
System.err.println("URL Exception: "+ex.getMessage());
}
不幸的是,运行客户端应用程序时引发了以下异常:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: invalid argument: can't kill an exited process
...
Driver info: driver.version: unknown
最佳答案
在初始化Webdriver实例之前提供geckodriver路径,
try {
DesiredCapabilities capability = DesiredCapabilities.firefox();
System.setProperty("webdriver.gecko.driver", "/PATH_OF_DRIVER/geckodriver.exe");
driver = new RemoteWebDriver(new URL("http://Hub_IP/wd/hub"), capability);
capability.setBrowserName("firefox");
driver.get("https://www.google.com");
} catch (MalformedURLException ex) {
System.err.println("URL Exception: "+ex.getMessage());
}