0

I am trying to run tests with selenium in python, but it can not be recognized.

I have tried uninstalling with pip uninstall selenium and reinstalling, and it has not worked.

When i run import selenium i get this error:

import selenium
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named selenium

But, when I run pip install selenium, I get:

Requirement already satisfied: selenium in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (3.141.0)
Requirement already satisfied: urllib3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from selenium) (1.25.9)

I am not sure if Selenium is just in the wrong place on my machine so it can not be recognized, or what is going on.

Thanks

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

There are a number of reasons this may fail. The easiest to validate is if it is available in the environment you are working?

Check by running pip list from terminal while in the environment you are running your python module or notebook from.

Can you say if you’re using a venv?

Also, I think you typically from selenium import webdriver not selenium alone.

Check out this question

MaxPi
  • 719
  • 1
  • 6
  • 12
0

This error message...

import selenium 

Traceback (most recent call last): File "", line 1, in ImportError: No module named selenium

...implies that there was an error while invoking the Selenium module.


Analysis

On executing the line of code:

pip install selenium

As you are seeing the message:

Requirement already satisfied: selenium in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (3.141.0)
Requirement already satisfied: urllib3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from selenium) (1.25.9)

implies that Selenium is already installed in your system.


Solution

Presumably, instead of using:

import selenium

You need to use:

from selenium import webdriver

Reference

You can find a relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352