OS: Win32
Selenium Version: 2.53.2
Browser: phantomjs, which installed by npm install phantomjs-prebuilt
Browser Version: 2.1.7
npm install selenium-webdriver
npm install phantomjs-prebuilt
node js source
const driver = new WebDriver.Builder()
.withCapabilities(
WebDriver.Capabilities.phantomjs()
).build()
should find phantomjs executable, and return success.
cant find phantomjs executable.
test\node_modules\selenium-webdriver\phantomjs.js:80
throw Error(
^
Error: The PhantomJS executable could not be found on the current PATH. Please download the latest version from http://phantomjs.org/download.html and ensure it can be found on your PATH. For more information, see https://github.com/ariya/phantomjs/wiki
at Error (native)
...
step 1. open cmd window
step 2. run
mkdir test
cd test
npm install selenium-webdriver
npm install phantomjs-prebuilt
step 3. then run this node js source
const WebDriver = require('selenium-webdriver')
const driver = new WebDriver.Builder()
.withCapabilities(
WebDriver.Capabilities.phantomjs()
).build()
step 4. webdriver said that cant find phantomjs executable.
step 1. find executable installed by phatomjs-prebuilt in node_modules.bin
D:\test>dir node_modules\.bin\phantomjs*
node_modules\.bin 的目录
2016/05/09 11:59 335 phantomjs
2016/05/09 11:59 212 phantomjs.cmd
step 2. reason: in selenium-webdriver/phantomjs.js:
const PHANTOMJS_EXE =
process.platform === 'win32' ? 'phantomjs.exe' : 'phantomjs';
it only find .exe . but the phantomjs-prebuilt installed executable name is .cmd
step 3. fix: add .cmd to search io.findPath:
function findExecutable(opt_exe) {
const PHANTOMJS_CMD = 'phantomjs.cmd'
var exe = opt_exe || io.findInPath(PHANTOMJS_EXE, true) || io.findInPath(PHANTOMJS_CMD, true);
Marking this as a feature request as we've never claimed to support phantomjs-prebuilt. I will not accept a PR that introduces a dependency on that module, but would consider a PR that made selenium-webdriver aware of it when searching for the executable.
thanks. please support search .cmd file, because when we use npm in win32, almost all executable installed in node_modules/.bin is named with a ".CMD" ext.
Happened to be working with this issue and found that you can technically get around this by building a PhantomJS driver around a custom Capability linking to the location of the executable.
You just write something like this in the beginning of your own test, no need to modify selenium's code:
//setup custom phantomJS capability
const phantomjs_exe = require('phantomjs-prebuilt').path;
var customPhantom = selenium.Capabilities.phantomjs();
customPhantom.set("phantomjs.binary.path", phantomjs_exe);
//build custom phantomJS driver
const driver = new selenium.Builder().
withCapabilities(customPhantom).
build();
Since Selenium provides instructions for how to work with a custom Firefox install, I wrote instructions for how to use phantomjs-prebuilt with selenium-webdriver here
@vtange ah, this is good. because at last I need not to hard code the PATH in my code.
thanks!
Seconded @jleyba on not putting dependency on phantom-js-prebuilt.
That project has a known problematic install with CDN flakkiness, there is a myriad of issues filed against this.
See:
And https://github.com/Medium/phantomjs/pull/598#issuecomment-249285918
Where we explain the root cause. We have removed this dependency from our CI pipeline completely.
There are also other alternative to configure phantomjs support out of the box.
E.g. with a library like _selenium-standalone_ maintained by the folks at Saucelabs.
See - https://www.npmjs.com/package/selenium-standalone
You will have to configure the way you build your driver to use this library and just specify phantomjs as the configuration parameter.
new webdriver.Builder().usingServer(`http://${selenium.hostname}:${selenium.port}/wd/hub`);
with the following parameters
selenium: {
hostname: 'localhost',
port: '4444'
}
Also with headless chrome coming out soon, it might be worth it to transition to use Chrome all together
With the phantomjs npm package being deprecated and phantomjs-prebuilt becoming the recommendation, is there any change in support expected?
with chrome headless now being available - Should this still be an option?
@manoj9788 I just start to use chrome headless today.
const options = {
args: [
'--disable-gpu',
'--headless', // https://developers.google.com/web/updates/2017/04/headless-chrome
'--homepage=about:blank',
'--no-sandbox',
], // issue #26 for run inside docker
See:
Nice, so can you close this issue?
Thanks
You are welcome. :)
Most helpful comment
Happened to be working with this issue and found that you can technically get around this by building a PhantomJS driver around a custom Capability linking to the location of the executable.
You just write something like this in the beginning of your own test, no need to modify selenium's code:
Since Selenium provides instructions for how to work with a custom Firefox install, I wrote instructions for how to use phantomjs-prebuilt with selenium-webdriver here