例外:必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径;与远程WebDriver [英] Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property; with Remote WebDriver

查看:714
本文介绍了例外:必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径;与远程WebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我修改代码以与RemoteWebDriver和ChromeDriver一起运行时,我得到:异常:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;

When I modified my code to run with RemoteWebDriver and ChromeDriver I am getting: Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property;

代码:

File file = new File("C:/WebDrivers/chromedriver.exe");
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", Path_FileDownload);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL("http://192.168.224.160:4444/wd/hub"), cap);
//driver = new ChromeDriver(cap);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

文件在我运行它的PC上存在.当我切换到ChromeDriver而不是Remote WebDriver时,效果很好.

The file exists on the PC that I am running it on. When I switch to ChromeDriver instead of Remote WebDriver is works just fine.

推荐答案

File file = new File("C:/WebDrivers/chromedriver.exe");
System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());

仅在使用ChromeDriver时起作用.我将此模式称为local模式,即运行测试用例的JVM也会从浏览器中分离出来.

work only when you use ChromeDriver. I call this mode as local mode i.e., the JVM which runs the test case also spins off the browser.

当您使用RemoteWebDriver时,您正在以remote模式工作,因为剥离您的测试用例的JVM与另一个JVM(硒节点)进行对话以剥离浏览器.

When you use RemoteWebDriver you are working in a remote mode, because the JVM that spins off your test case, talks to another JVM (The selenium node) to spin off the browser.

使用RemoteWebDriver时,您尝试通过集线器连接到作为节点运行的其他JVM.

When you are working with RemoteWebDriver, you are trying to connect to a different JVM running as the node through the hub.

对于此用例,您需要在运行节点的机器中执行以下操作之一:

For this use-case you would need to do one of the following in the machine wherein your node is running:

  • C:\WebDrivers添加到您的PATH变量中.通过打开新的命令提示符并运行echo %PATH%,确保确认其添加正确.您应该在命令输出中看到C:\WebDrivers. (或)
  • 通过添加webdriver.chrome.driver作为JVM参数来启动节点.例如,如下所示:java -Dwebdriver.chrome.driver=C:\WebDrivers\chromedriver.exe -jar selenium-server-standalone-2.53.1.jar -role node
  • Add C:\WebDrivers to your PATH variable. Make sure you confirm its added properly by opening up a new command prompt and running echo %PATH%. You should see C:\WebDrivers in the command output. (or)
  • Start your node by adding webdriver.chrome.driver as a JVM argument. For e.g., something like this : java -Dwebdriver.chrome.driver=C:\WebDrivers\chromedriver.exe -jar selenium-server-standalone-2.53.1.jar -role node

这篇关于例外:必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径;与远程WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆