VS Code Selenium Issue : - selenium

Issue is seen in selenium, selenium module not found even after installation of selenium via pip.
I have already installed pip in windows (global). It is working in Pycharm and other apps.
Driver Fine
working fine in Pycharm.
# Importing Selenium
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
# Terminal :
PS C:\Users\sudip neupane> pip3 install selenium
***Requirement already satisfied: selenium in c:\users\sudip*** neupane\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (3.141.0)
Requirement already satisfied: urllib3 in c:\users\sudip neupane\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from selenium) (1.26.5)
PS C:\Users\sudip neupane>
# ERROR
from selenium import webdriver
ModuleNotFoundError: ***No module named 'selenium***'

I found this issue was caused by having two python versions installed in my machine.
This worked after Reinstallation and Removing path from VS code while installing.
this can be solved by :
open file in VS Code and click CTRL+SHIFT + P
search -> Python: Select Interpreter
select any interpreter from list or and new Interpreter.
verify that selected interpreter have selenium modules.
Thanks!

Related

Running Selenium in Google Colab without getting this error

I have been using Selenium in Google Colab to do some scrapping for some time now. I use:
# install chromium, its driver, and selenium
!apt update
!apt install chromium-chromedriver
!pip install selenium
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
wd.get("https://www.website.com")
print(wd.page_source) # results
And until today it worked perfectly, but today I ran this code and it started giving this error:
ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)
I have tried manually installing typing.py, I've tried updating the python version, but nothing has worked. Can some one please help me to run Selenium (with Chrome) in Google Colab?
I've noticed that the same error happens in all answers I have found about this topic such as:
How to use Selenium on Colaboratory Google?
https://colab.research.google.com/github/restrepo/ComputationalMethods/blob/master/tools/selenium.ipynb
https://gist.github.com/korakot/5c8e21a5af63966d80a676af0ce15067

The computer cannot find the file specified and Win32 error

Whenever I try to use Selenium module after pip installing the module it shows this error. I am not able to run my code and it continuously shows this error. It shows Win32 error. It also shows chromedriver executable needs to be in Path.
Try to use webdriver-manager package:
pip install webdriver-manager
the code should look like this:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
The module download driver automatically and store it at known path for selenium. It will solve all of kinda troubles with driver path

The system cannot find the file specified and Win32 error

Whenever I try to use Selenium module after pip installing the module it shows this error.
I am not able to run my code and it continuously shows this error. It shows Win32 error.
It also shows chromedriver executable needs to be in Path.
Try to use webdriver-manager package:
pip install webdriver-manager
the code should look like this:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
The module download driver automatically and store it at known path for selenium. It will solve all of kinda troubles with driver path

Sikulix and Selenium integration in Pycharm project

Looking for step-by-step instructions how to integrate Sikulix with Selenium in Pycharm IDE. Would like to combine Sikuli and selenium webdriver for unittesting.
I have already downloaded SikuliX as standalone IDE for Jython2.7. In my Pycharm IDE I have some sikuli packages available. See attached. I do not know which ones to download. Also, still confused if I need to dowload Jython or not.
Please help.
1) Download selenium python bindings from https://pypi.python.org/simple/selenium/
2) Extract that to a folder and run python setup.py install from there.
3) Now, copy the generated "selenium" folder to your \python\Lib and \jython\Lib root directories
4) Test your code by typing "from selenium import webdriver" in your file.
5) For sikuli, just edit your pycharm run configuration and include this in your environment variables "CLASSPATH=C:\Sikuli\sikulixapi.jar;PYTHONUNBUFFERED=1"
6) Use jython as your project interpreter

Pycharm can not auto complete selenium package

I install selenium through Python pip and write a simple file called crawlTest.py, it works well.Later, I install Pycharm and try to auto complete method from selenium, but it doesn't work.
I guess Pycharm didn't know where I install selenium and an external library is needed.But I try by myself and search on google and StackOverflow, I didn't get proper solution.
I have read the flowing posts, but still not work. It is very useful and
time-saving for those who use selenium and Pycharm if some one could give me .
here is post list I hava viewed:
How to get PyCharm to auto-complete code in methods?
PyCharm doesn't auto-completes very simple cases such as: import pickle
I install selenium by python pip, and it works with python3.5,but not python 2.7. so I changed my project interpreter as python 3.5 in Py . Now it works!
for use auto-complete Pycharm feture go to "File\Setting\Project:" add new interpreter and select you instaleed python directory.