0
votes

I'm doing a unit testing for my javascript codes. I prefer to use a headless browser for easier running. It goes well when I installed some dependencies but when I install phantomjs, it has an error.

C:\Phantomjs>npm install -g phantomjs npm WARN deprecated [email protected]: Package renamed to phantomjs-prebuilt. Plea se update 'phantomjs' package references to 'phantomjs-prebuilt' npm WARN deprecated [email protected]: Use uuid module instead npm WARN deprecated [email protected]: ReDoS vulnerability parsing Set-Cookie h ttps://nodesecurity.io/advisories/130 C:\Users.ra\AppData\Roaming\npm\phantomjs -> C:\Users.ra\AppDa ta\Roaming\npm\node_modules\phantomjs\bin\phantomjs

[email protected] install C:\Users.ra\AppData\Roaming\npm\node_modules\ phantomjs node install.js

Considering PhantomJS found at C:\Users.ra\AppData\Roaming\npm\phantomj s.CMD Looks like an npm install -g on windows; skipping installed version. Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phanto mjs-2.1.1-windows.zip Saving to C:\Users.ra\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-wind ows.zip Using proxy http://.ra:******@proxy:3128/ Receiving...

Error making request. Error: tunneling socket could not be established, statusCode=502 at ClientRequest.onConnect (C:\Users.ra\AppData\Roaming\npm\node_mo dules\phantomjs\node_modules\tunnel-agent\index.js:165:19) at Object.onceWrapper (events.js:320:30) at emitThree (events.js:135:13) at ClientRequest.emit (events.js:216:7) at Socket.socketOnData (_http_client.js:470:11) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at addChunk (_stream_readable.js:264:12) at readableAddChunk (_stream_readable.js:251:11) at Socket.Readable.push (_stream_readable.js:209:10)

Please report this full log at https://github.com/Medium/phantomjs npm WARN Error: EPERM: operation not permitted, scandir 'C:\Users.ra\Ap pData\Roaming\npm\node_modules\phantomjs\node_modules\dashdash\node_modules' npm WARN { Error: EPERM: operation not permitted, scandir 'C:\Users.ra \AppData\Roaming\npm\node_modules\phantomjs\node_modules\dashdash\node_modules' npm WARN stack: 'Error: EPERM: operation not permitted, scandir \'C:\Users\p ardillo.ra\AppData\Roaming\npm\node_modules\phantomjs\node_modules\dashda sh\node_modules\'', npm WARN errno: -4048, npm WARN code: 'EPERM', npm WARN syscall: 'scandir', npm WARN path: 'C:\Users\.ra\AppData\Roaming\npm\node_modules\p hantomjs\node_modules\dashdash\node_modules' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] install: node install.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] install script. npm ERR! This is probably not a problem with npm. There is likely additional log ging output above.`

What should I do?

2
Run as administratorAyush Gupta
Still the same @AyushGuptaR.A.P
what's your npm version?Ayush Gupta
npm --version is >> 5.4.2R.A.P

2 Answers

1
votes

The simplest installation method is

  1. Install NodeJS
  2. Using Node's package manager install phantomjs: npm -g install phantomjs-prebuilt

After installation, you may use phantom as simple as:

driver = webdriver.PhantomJS() # or add to your PATH
driver.set_window_size(1024, 768) # optional
driver.get('https://google.com/')
driver.save_screenshot('screen.png') # save a screenshot to disk
sbtn = driver.find_element_by_css_selector('button.gbqfba')
sbtn.click()

If your system path environment variable isn't set correctly, you'll need to specify the exact path as an argument to webdriver.PhantomJS(). Replace this:

driver = webdriver.PhantomJS() # or add to your PATH

... with the following:

driver = webdriver.PhantomJS(executable_path='/usr/local/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs')

References:

0
votes

Try run npm install phantomjs-prebuilt

phantomjs name changed to phantomjs-prebuilt on Pre-2.0 version release.

Source: view this link for detailed description of the name change.