question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: support phantomjs-prebuilt in selenium-webdriver

See original GitHub issue

Meta -

OS: Win32

Selenium Version: 2.53.2

Browser: phantomjs, which installed by npm install phantomjs-prebuilt

Browser Version: 2.1.7

Expected Behavior -

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.

Actual Behavior -

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)
    ...

Steps to reproduce -

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.

Steps to quick fix -

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);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
vtangecommented, May 11, 2016

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

1reaction
jleybacommented, May 9, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: support phantomjs-prebuilt in selenium-webdriver
Feature request : support phantomjs-prebuilt in selenium-webdriver. ... Selenium Version: 2.53.2. Browser: phantomjs, which installed by npm install ...
Read more >
Is there a way to use PhantomJS in Python? - Stack Overflow
The easiest way to use PhantomJS in python is via Selenium. The simplest installation method is. Install NodeJS; Using Node's package manager install ......
Read more >
mocha vs phantomjs-prebuilt vs puppeteer vs selenium-webdriver ...
Finally, come chat with the maintainers on Gitter if you want to help with: Triaging issues, answering questions; Review, merging, and closing pull...
Read more >
PhantomJS - Scriptable Headless Browser
PhantomJS is a headless web browser scriptable with JavaScript. It runs on Windows, macOS, Linux, and FreeBSD. Using QtWebKit as the back-end, it...
Read more >
phantomjs-prebuilt | Yarn - Package Manager
An NPM installer for PhantomJS, headless webkit with JS API. Build Status. Building and Installing. npm install phantomjs-prebuilt. Or grab the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found