Cody Kutac
Cody Kutac

Reputation: 93

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

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.

Upvotes: 1

Views: 2113

Answers (3)

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14736

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

Upvotes: 1

Varun Gattu
Varun Gattu

Reputation: 43

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

Upvotes: 0

otoomey
otoomey

Reputation: 999

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.

Upvotes: 0

Related Questions