Selenium driver location search path
Asked Answered
A

2

9

I'm trying to set up selenium tests in nCrunch which outputs the tests to its own temp folder.

I'm getting the following error when I create the driver (new PhantomJSDriver()):

OpenQA.Selenium.DriverServiceNotFoundException : The PhantomJS.exe file does not exist in the current directory or in a directory on the PATH environment variable.

However I have checked and PhantomJS.exe does exist in the current directory (\bin\debug).

I then tried using new PhantomJSDriver(".\\") which should be the current directory and that does work.

What is the "current directory" Selenium is referring to in this message?

Alcazar answered 2/11, 2015 at 2:49 Comment(3)
A very useful tool for this type of scenario is Microsoft's process explorer: technet.microsoft.com/en-ca/sysinternals/bb896653.aspx Set a breakpoint just before the new(), turn on process explorer, and step over the error. Process Explorer will show where in the filesystem it lookedVellum
You can look into the source code to determine the search path logic.Fault
@Luke McGregor Please check the following post, it's in JAVA however might help you. #42273903Blowfly
P
1

Rather than assuming ".\\", get the current working working directory by Directory.GetCurrentDirectory or System.AppDomain.CurrentDomain.BaseDirectory . Take a look at Get current folder path.

Paymar answered 16/1, 2018 at 9:8 Comment(0)
R
1

new PhantomJSDriver() will use your bin folder

if PhantomJS.exe does not exist there, try to find where it's located and insert full path in constructor

new PhantomJSDriver("real_path_to_PhantomJS.exe")
Roush answered 12/1, 2020 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.