我的Selenium Grid显示错误:
org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property;
但我完全指定了它(根据我的知识)
System.out.println("googlechrome");
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
System.setProperty("webdriver.chrome.driver", "D:\\testing\\zip file\\chromedriver_win_26.0.1383.0\\chromedriver.exe");
driver = new ChromeDriver();
我不知道出了什么问题。上周相同的代码完美运行,但现在却没有。
答案 0 :(得分:10)
如果您正在运行Grid,则需要在节点中设置Chromedriver可执行文件:
java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.chrome.driver=lib\chromedriver.exe
最重要的部分是-D
切换器,它位于Chrome浏览器设置之后。
另外,如果您运行多个节点,则该路径必须指向具体计算机(节点)上的chromedriver可执行文件。这就是为什么我把它作为相对路径而不是绝对路径......
答案 1 :(得分:1)
这不是你需要的吗?
File file = new File("D:\testing\zip file\chromedriver_win_26.0.1383.0\chromedriver.exe");
system.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver = new ChromeDriver(capability);