Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property; with Remote WebDriver

…衆ロ難τιáo~ 提交于 2019-12-11 06:57:33

问题


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;

Code:

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);

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.


回答1:


The lines

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

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.

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.

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:

  • 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



回答2:


You have two slashes at the start of your path:
"C://WebDrivers" + "/chromedriver.exe"
should be
"C:/WebDrivers" + "/chromedriver.exe"

Java file paths use '/' to separate directories and files, same as UNIX based systems.




回答3:


    ChromeOptions options = new ChromeOptions();
    options.setBinary("Chrome_Binary/chrome.exe");
    options.addArguments("--start-fullscreen");
    System.setProperty("webdriver.chrome.driver", "Drivers/Chrome/chromedriver.exe");
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(ChromeOptions.CAPABILITY, options);


来源:https://stackoverflow.com/questions/45598662/exception-the-path-to-the-driver-executable-must-be-set-by-the-webdriver-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!