The “attributeerror: module selenium. webdriver has no attribute phantomjs“ error message occurs because PhantomJS has been deprecated or removed.
Actually, there is no problem with your Python script; the problem is that Selenium is no longer supporting PhantomJS in its latest version. So, every time you try to access the PhatomJs, it doesn’t exist.
In this article, we’ll show you the solutions if you are having a hard time figuring out how to fix this “module selenium.webdriver has no attribute phantomjs” error. Stick to this article, as we are going to explain in detail the important things that you should know.
What is “attributeerror: module selenium.webdriver has no attribute phantomjs” error?
This attribute error module selenium.webdriver has no attribute phantomjs error message indicates that there is no “phantomjs” attribute in the Selenium WebDriver module.
PhantomJS browser has been deprecated in favor of other headless browsers such as Chrome or Firefox.
It is no longer supported by Selenium which is why when you are trying to access PhantomJS in selenium.webdriver it will result an error.
How to fix “attributeerror: module selenium.webdriver has no attribute phantomjs” error?
As mentioned above this error happens because PhantomJS has been deprecated. However there are many ways to fix this error.
Solution 1: Use different webdriver or browsers
You can use other headless browsers like Chrome or Firefox. Alternatively, you can also update your Python script and use a different webdriver like GeckoDriver or ChromeDriver instead of using PhantomJS.
from selenium import webdriver browser = webdriver.PhantomJS() browser.get('http://www.google.com')
If you are using the above code, an error “AttributeError: ‘module’ object has no attribute ‘PhantomJS‘” will definitely occur because webdriver doesn’t recognize PhantomJS. Instead, try to use the Python code below:
from selenium import webdriver driver = webdriver.Chrome() driver.get("http://www.google.com/")
Solution 2: Install Older Version
The latest version of Selenium doesn’t have the attribute PhantomJS. So to fix this “attributeerror: module selenium.webdriver has no attribute phantomjs” error, you have to degrade the Selenium version.
1. You have to uninstall selenium first, using the following command:
pip uninstall selenium
Then, you have to install selenium to the older version.
2. To install selenium to your desired version you may use the following command:
pip install selenium==2.48.0
pip install -U selenium==3.3.0
Note: It will run your Python script perfectly. However, there are some cases where other modules in your Python script do not support the older version of Selenium; you just have to make sure there is no conflict.
To check selenium version, you can use the following commands:
pip show -V selenium
pip show selenium
If you want to update the version you can use the following command:
pip install -U selenium
Related Articles for Python Errors
- Attributeerror: module ‘numpy’ has no attribute ‘int’
- Attributeerror: module ‘cgi’ has no attribute ‘escape’
- Attributeerror: module ‘cv2’ has no attribute ‘_registermattype’
This article provides solutions for the attributeerror: module selenium.webdriver has no attribute phantomjs, which is a big help in solving the problem you are currently facing.
Thank you very much for reading to the end of this article. Just in case you have more questions or inquiries, feel free to comment, and you can also visit our website for additional information.