Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

module 'selenium.webdriver' has no attribute 'PhantomJS'

Writer Emily Wong

I am running PhantomJS by

driver = webdriver.PhantomJS(executable_path='E:\phantomjs\bin\phantomjs.exe')

but the program fails, saying

AttributeError: module 'selenium.webdriver' has no attribute 'PhantomJS'.

OS is Windows 10. My python version is 3.6, selenium version is 3.8.0, and the phantomjs version is 2.1.1. All of them is newest.

Thanks if anyone could offer a hand!

Following is the screenshot of selenium version.

3

5 Answers

I drew attention to this question while I was looking for an answer to it in google. It took me quite a lot of work to find the answer to it, so in order to save some work for others, and although a lot of time has passed since this question, I advise you not to use PhantomJS at this moment. On the official site of Selenium you can read the quote: "PhantomJS is a headless browser based on Webkit, albeit a version much older than that used by Google Chrome or Safari. Whilst historically a popular choice, it would now be wise to avoid PhantomJS. The project has been unmaintained since the 5th of August 2017, so whilst the web will continue to change, PhantomJS will not be updated. This was after Google announced the ability to run Chrome headlessly, something also now offered by Mozilla’s Firefox.". I changed to Mozilla’s Firefox (I use it headlessly).

Your problem is not in code or anything is that the Selenium community stopped supporting PhantomJS in the new version, so every time you try to pull the PhatomJs lib it doesn't exist. In the documentation it says that they currently support

The native support for Opera and PhantomJS is removed in Selenium 4, as their WebDriver implementations are no longer under development. The Opera browser is based on Chromium, and users looking to test their implementation on Opera can opt for testing on the Chrome browser.

Install Older Version:

pip uninstall selenium
pip install -U selenium==3.3.0

ref : Full Explanation Link

As you are using the single quotes (\) in the path you should pass the raw (r) switch along as follows :

driver = webdriver.PhantomJS(executable_path=r'E:\phantomjs\bin\phantomjs.exe')

Update :

If the error still exists check the following through Command Prompt :

  • Check Selenium version :

    >pip show -V selenium

    You must see an output like :

    Name: selenium
    Version: 3.8.0
    Summary: Python bindings for Selenium
    Home-page:
    Author: UNKNOWN
    Author-email: UNKNOWN
    License: Apache 2.0
    Location: c:\python\lib\site-packages
    Requires:
  • Check all the packages installed :

    >pip freeze

    You must see an output like :

    Selenium==3.8.0

If the following commands Fails which means Selenium was not properly installed. So you have to do :

>pip install -U selenium

As an alternative you can uninstall Selenium and install again as follows :

>pip uninstall selenium
>pip install -U selenium

Here is the complete Installation Instructions for your reference.

3

I've solved the problem. The reason is that I use pycharm as IDE. And I create the project using virtual environment. That's why I cannot use the libraries I installed.

Anyway, thanks for your help!

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.