Selenium grid with Chrome driver (WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property)(带有 Chrome 驱动程序的 Selenium 网格(WebDriverException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置)) - IT屋-程序员软
问题描述
我正在尝试让我的 Selenium Grid 在 Chrome 驱动程序上运行.
I am trying to get my Selenium Grid running on Chrome driver.
一开始我启动了集线器和节点:java -jar selenium-server-standalone-2.45.0.jar -role hubjava -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register一个>
At first I started hub and node: java -jar selenium-server-standalone-2.45.0.jar -role hub java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register
然后我开始我的测试:
public class ChromeDriverTest {
private WebDriver driver = null;
String BaseURL,NodeURL;
@Before
public void before() throws Exception{
BaseURL="http://www.google.com";
NodeURL="http://localhost:4444/wd/hub";
File file = new File("C:\Users\pushkaryova\Desktop\Nexus\driver\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
DesiredCapabilities capa =DesiredCapabilities.chrome();
capa.setBrowserName("chrome");
capa.setPlatform(Platform.ANY);
driver=new RemoteWebDriver(new URL(NodeURL),capa);
}
@Test
public void GoogleSearch() throws Exception {
driver.get("http://www.google.com");
WebElement searchBox = driver.findElement(By.xpath("//div[3]/div/input[1]"));
hightlight(searchBox);
driver.findElement(By.xpath("//div[3]/div/input[1]")).clear();
driver.findElement(By.xpath("//div[3]/div/input[1]")).sendKeys("Test");
driver.findElement(By.xpath("//button")).click();
}
public void hightlight(WebElement webElement) throws InterruptedException {
for (int i = 0; i < 2; i++) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(
"arguments[0].setAttribute('style', arguments[1]);",
webElement, "color: red; border: 3px solid red;");
}
}
}
并得到一个错误:org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置
and get an error: org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property
我的代码有什么问题?
推荐答案
driver
可执行文件需要在节点机器上物理可用.您可以在启动node
The driver
executable needs to be avaiable physically on node machine. You can set the path to exe while starting the node
在命令中添加这一行
-Dwebdriver.chrome.driver=./chromedriver.exe
我从 json 文件中配置了这个,发现这更容易
I configure this from json file and found that's little easier
名为 DefaultNode.json 的 json 文件
{
"capabilities":
[
{
"browserName": "firefox",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"browserName": "chrome",
"maxInstances": 5,
"seleniumProtocol": "WebDriver"
},
{
"platform": "WINDOWS",
"browserName": "internet explorer",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration":
{
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"host": ip,
"register": true,
"registerCycle": 5000,
"hubPort": 4444,
"hubHost": ip
}
}
使用 json 配置启动节点
java -jar selenium-server-standalone-2.45.0.jar -role webdriver -nodeConfig DefaultNode.json -Dwebdriver.ie.driver=.IEDriverServer.exe
注意 IEDriverServer.exe 与 json
文件放在同一目录
Notice the IEDriverServer.exe is placed in same directory with json
file
这篇关于带有 Chrome 驱动程序的 Selenium 网格(WebDriverException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 Chrome 驱动程序的 Selenium 网格(WebDriverException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置)
基础教程推荐
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01