Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Selenium manager doesn't work in paths that contain spaces #11649

Closed
cfarmerga opened this issue Feb 13, 2023 · 6 comments
Closed

Comments

@cfarmerga
Copy link

What happened?

I am using Windows 11 and have a simple js script that tries to build a driver using selenium manager. I see that it works fine when I have the script in a path which contains no spaces, but it fails when spaces exist in the path with 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,ch
rome                                                                                                                                                                                             
'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(                                                                                                                                                                               
            ^        

I see that the cause seems to be the code in selenium-webdriver/common/seleniumManager.js (line 76), where the driverLocation function tries to use the result of getBinary() directly in execSync. It seems like this path should be quoted before being passed to execSync.

Also posted to https://stackoverflow.com/questions/75438848/selenium-builder-failing-with-spaces-in-path

How can we reproduce the issue?

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


Here's the relevant code:

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

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

Relevant log output

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,ch
rome                                                                                                                                                                                             
'c:\dev\selenium' is not recognized as an internal or external command,                                                                                                                          
operable program or batch file.

Operating System

Windows 11

Selenium version

javascript 4.8.0

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

Any

Are you using Selenium Grid?

No response

@github-actions
Copy link

@cfarmerga, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@surajverma255
Copy link

Meanwhile, we can eliminate the spaces with replaceAll() to make it understand the path.

@atrnh
Copy link
Contributor

atrnh commented Apr 6, 2023

Just in case it helps this get triaged sooner, here's the problematic line of code:

output = JSON.parse(execSync(args.join(' ')).toString())

Since execSync doesn't handle escaping shell metacharacters, I'm guessing we want to use spawnSync here instead? 🤔

We use Selenium in the classroom and this bug has been causing issues for our students. If no one has a chance to take a look at this, I might offer up a PR 😅

@titusfortner
Copy link
Member

@atrnh yes, we would love a PR! thank you.

atrnh added a commit to atrnh/selenium that referenced this issue Apr 7, 2023
Since execSync does not escape shell metacharacters, attempting to
execute a command with a space in it will fail. This is the case when
the path to selenium-manager contains a space. This commit replaces
execSync with spawnSync, which does escape shell metacharacters.

Fixes SeleniumHQ#11649
atrnh added a commit to atrnh/selenium that referenced this issue Apr 7, 2023
Since execSync does not escape shell metacharacters, attempting to
execute a command with a space in it will fail. This is the case when
the path to selenium-manager contains a space. This commit replaces
execSync with spawnSync, which does escape shell metacharacters.

Fixes SeleniumHQ#11649
@atrnh
Copy link
Contributor

atrnh commented Apr 7, 2023

@atrnh yes, we would love a PR! thank you.

Thanks for the response @titusfortner! I've submitted a PR 😊

@diemol diemol added this to the 4.9 milestone Apr 18, 2023
@diemol diemol closed this as completed in a5b0ad9 Apr 20, 2023
dev-ardi pushed a commit to dev-ardi/selenium that referenced this issue Apr 24, 2023
…eniumHQ#11649) (SeleniumHQ#11873)

* replace execSync with spawnSync in seleniumManager.js

Since execSync does not escape shell metacharacters, attempting to
execute a command with a space in it will fail. This is the case when
the path to selenium-manager contains a space. This commit replaces
execSync with spawnSync, which does escape shell metacharacters.

Fixes SeleniumHQ#11649

* [javascript] Refine usage of spawnSync

---------

Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com>
Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
Co-authored-by: Diego Molina <diemol@gmail.com>
Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants