0

I have a simple script to try to use the Selenium Manager to build a chrome driver for my test in Windows. It works fine when it's located in a path with no spaces ("c:\dev\selenium-test") but fails when in a path containing spaces ("c:\dev\selenium path with space"). I need to be able to deploy this script to an arbitrary directory that may contain spaces. How can I accommodate spaces in the current directory?

Here's my package.json and code below.

{
  "type": "commonjs",
  "dependencies": {
    "selenium-webdriver": "4.8.0"
  }
}

const { Builder, Browser } = require("selenium-webdriver");

(async function example() {
  const driver = await new Builder().forBrowser(Browser.CHROME).build();
  driver.get("https://stackoverflow.com");
})();

When I run from a non-space path, the browser launches with the correct url. When I run from a space-containing path, I get this error:

c:\dev\selenium path with space>node simple.js
 The ChromeDriver could not be found on the current PATH, trying Selenium Manager
'c:\dev\selenium' is not recognized as an internal or external command,
operable program or batch file.
Unable to obtain driver using Selenium Manager: Error: Error executing command with c:\dev\selenium path with space\node_modules\selenium-webdriver\bin\windows\selenium-manager.exe,--browser,chrome
'c:\dev\selenium' is not recognized as an internal or external command,
operable program or batch file.

c:\dev\selenium path with space\node_modules\selenium-webdriver\chrome.js:175
      throw Error(
            ^

It looks like this problem can be fixed if seleniumManager.js quotes its path when it's trying to get the path to the selenium-manager.exe binary. Is there any good way to accommodate these paths without modifying seleniumManager.js code?

Chris Farmer
  • 24,974
  • 34
  • 121
  • 164

0 Answers0