8

Running Selenium locally on flask. Im using the PhantomJS driver. I previously had a path error:

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. 

But after finding out from another StackOverflow question, I learned that I have to pass the environment path as a parameter for PhantomJS. The path I have below is the path to the phantomJS folder in my virtual environment folder.

driver = webdriver.PhantomJS(executable_path='/Users/MyAcc/Documents/MYWEBAPP/venv/lib/python3.5/site-packages/selenium/webdriver/phantomjs')

However, I get a new error-code now:

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable may have wrong permissions.

Here's what I get when I check the file permissions of the path.

total 40 
drwxr-xr-x 7 USER staff 238 Nov 6 00:07 . 
drwxr-xr-x 17 USER staff 578 Nov 6 00:03 .. 
-rw-r--r--@ 1 USER staff 6148 Nov 6 00:07 .DS_Store 
-rw-r--r-- 1 USER staff 787 Oct 31 12:27 __init__.py 
drwxr-xr-x 5 USER staff 170 Oct 31 12:27 __pycache__ 
-rw-r--r-- 1 USER staff 2587 Oct 31 12:27 service.py 
-rw-r--r-- 1 USER staff 2934 Oct 31 12:27 webdriver.py 
Tahir
  • 81
  • 1
  • 1
  • 3
  • and what permission has this file when you list directory `ls -al` - `rwxrwxrwx` ? – furas Nov 06 '16 at 04:57
  • `total 40` `drwxr-xr-x 7 USER staff 238 Nov 6 00:07 .` `drwxr-xr-x 17 USER staff 578 Nov 6 00:03 ..` `-rw-r--r--@ 1 USER staff 6148 Nov 6 00:07 .DS_Store` `-rw-r--r-- 1 USER staff 787 Oct 31 12:27 __init__.py` `drwxr-xr-x 5 USER staff 170 Oct 31 12:27 __pycache__` `-rw-r--r-- 1 USER staff 2587 Oct 31 12:27 service.py` `-rw-r--r-- 1 USER staff 2934 Oct 31 12:27 webdriver.py` – Tahir Nov 06 '16 at 05:07
  • did you solved the issue? Thasnk you – Joan Triay May 11 '17 at 23:11

7 Answers7

2

I placed the phantomjs file into /usr/local/bin and it worked fine.

Joe Daniels
  • 155
  • 7
2

Well I got this solved by the following CODE:

browser = webdriver.PhantomJS(executable_path = "/usr/local/Cellar/phantomjs/2.1.1/bin/phantomjs")
Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
Nabin Bhusal
  • 129
  • 1
  • 2
  • 7
  • it also works for me in windows 10. the "phantomjs" in the end is phantomjs.exe, not a fold. – Renke Dec 02 '17 at 10:05
1

I met this problem before about python+phanomjs. solution:

Linux

putting phantomjs in /usr/local/share

Windows

putting phantomjs in /python/scripts

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
E.choose
  • 11
  • 2
1

I think the true reason for you problem is that: The phantomjs which webdrive needs is not the one under selenium/webdriver fold. When you use anaconda to install this package, it's really confusing (at least for me).

  • First install it with conda install -c conda-forge phantomjs, test it with phantomjs --version.
  • Then you can find the true phantomjs.exe in this fold: "path = /${home_path}/anaconda3/envs/${env_name}/bin/phantomjs". To test if it's the true path, test with /${home_path}/anaconda3/envs/${env_name}/bin/phantomjs --version. It should output __version__ information correctly.
  • Pause this path to webdriver.PhantomJS(executable_path=path) and it will be fixed.

So there's no need to use chmod or put it in /usr/local/bin (in this way, the only goodness is that you can skip the executable parameter)

Yixuan Wei
  • 165
  • 5
0
executable_path = './phantomjs-2.1.1-linux-x86_64/bin/phantomjs'

service_log_path = './log/ghostdriver.log'

driver = webdriver.PhantomJS(executable_path=executable_path, service_log_path=service_log_path)

You can use both the relative path and absolute paths.

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
LWX
  • 37
  • 6
0

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable may have wrong permissions.

This error is because phantomjs didn't execute permission, as long as for phantomjs - 2.1.1 - Linux - x86_64 / bin/phantomjs add execute permissions, chmod u + x phantomjs

Dharman
  • 30,962
  • 25
  • 85
  • 135
LWX
  • 37
  • 6
  • Welcome to Stack Overflow, do not post answer twice, edit your first answer and make the changing there, spend some time reading [how to write an answer](http://stackoverflow.com/help/how-to-answer). – Hizqeel Mar 06 '17 at 08:47
-1

Strangely, for me it was fixed by putting phantomjs in /usr/local/share and adding some symbolic links. I followed these steps:

  • move the phantomjs folder to /usr/local/share/:
    • sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /usr/local/share/.
  • create the symbolic links:
    • sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs
    • sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs

I'm no Linux expert so I don't know why this makes a difference. If anyone wants to pitch in, feel free.

Community
  • 1
  • 1
Peter
  • 13,733
  • 11
  • 75
  • 122