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?

undefined
  • 33,537
  • 22
  • 129
  • 198
  • A very useful tool for this type of scenario is Microsoft's process explorer: https://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 looked – Jared Dykstra Nov 02 '15 at 04:12
  • You can look into the source code to determine the search path logic. – Artjom B. Nov 02 '15 at 06:57
  • @Luke McGregor Please check the following post, it's in JAVA however might help you. http://stackoverflow.com/questions/42273403/how-to-enable-phantomjs-webdriver-in-selenium/42275761#42275761 – Gaurang Shah Feb 16 '17 at 14:38

2 Answers2

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.

ArunPrakash
  • 138
  • 1
  • 7
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")
Serhii Matvienko
  • 292
  • 3
  • 15