[WinError 2]FileNotFoundError in python Selenium webDriver - python

I'm started to learn python Selenium. I just downloaded by pip pip install python-selenium and started to write first lines and at this moment appeares
>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> driver = webdriver.Firefox()
[WinError2] FileNotFoundError...
...
Then I tried it with Chrome but appeares the same thing. Who can solve this problem?

You do following things and check whether it works.
Upgrade python bindings using
pip install -U selenium
for chrome download the latest chrome driver "ChromeDriver 2.45"
and write the code
from selenium import webdriver
driver=webdriver.Chrome("Path of the Chromedriver" + "chromedriver.exe" )

Related

no code runs after defining webdriver in selenium

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
print("hello world")
running python 3.10 on linux ubuntu
I was trying to play aruond with selenium however any code that I write after defining the webdriver does not work.
it seems that the interpreter gets stuck after defining the webdriver. it opens the webdriver but only shows "data:," and nothing else and won't respond to any code written after.
Chromium support is limited on selenium in my experience.
Please look at the replies here which do mention chromium-driver and how to get it
sudo apt-get install chromium-chromedriver
Should get you chromium driver and they have some example code there that doesn't look too outdated.
I figured out the problem, I only had chromium installed on my computer and I assumed that the chromium drivers and the chrome drivers are the same thing(still can't find any refrence to the chromium drivers)

Running selenium issue

I'm new to selenium just started learning it using freecodecamp and started using selenium
downloaded selenium using the following command in python
pip install selenium
And I manually installed chrome web driver.
Written the code as:
import os
from selenium import webdriver
os.environ["PATH"] +=r"C:/seleniumDrivers" #where the chrome driver is installed
driver = webdriver.Chrome()
The following error occured when I run this:
line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be
in
PATH. Please see https://chromedriver.chromium.org/home
But if I modified code a bit:
import os
from selenium import webdriver
driver = webdriver.Chrome("C:/seleniumDrivers/chromedriver.exe)
A pop website appeared and closes immediately.
Can anyone please suggest what should I do.
In the newer selenium, including the webdriver is depreciated. Use ChromeDriverManager instead of referencing the path to chromedriver.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import Select
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(ChromeDriverManager().install())
For the first issue
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
You have to point the PATH to the correct directory, which containing the chromedriver.exe executable on the first level (i.e. you can see the executable when you open the path, it usually named bin)
For the second issue
A pop website appeared and closes immediately. Can anyone please suggest what should I do.
It is because the code has finished (no further code to execute), so the program exits and closes the browser. You can try adding input() after the last line to see if the browser remains open (until you press enter on the command line).
You don't need to use the os module unless this is specific to your script, you can save the path as a variable. I'm using Selenium currently and this should work for you - you need to specify the "Service" now in the webdriver. Do the 2 pip installs first in terminal.
# pip install selenium #
# pip install webdriver-manager #
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
service = Service("C:/seleniumDrivers/chromedriver.exe")
driver = webdriver.Chrome(service=service)
driver.get(URL)

Python test using selenium cannot perform simple test

I am trying to learn about Selenium but I am not able to get even a simple program to test. Selenium webdriver seems to not be cooperating with Firefox and I am very frustrated, so I come to Stack Overflow for help.
For background, I use Python, can install with pip, and know command line.
I am on windows 10, firefox 48, and selenium webdriver 3 with python 3.5.2
Whenever I run the selenium test, (it opens a Firefox windows and the selenium website)
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.seleniumhq.org')
I always get an error:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: C:\ ... \AppData\Local\Temp\tmp68m5rtwt If you specified a log_file in the FirefoxBinary constructor, check it for details
It also opens a firefox window and has the link of about:blank&utm_content=firstrun(not a valid url)
I have looked across the internet for a similar situation, but nothing really close. I also tried many tutorials and made sure that I installed selenium the right way. I noticed that firefox was recently updated, but I am not sure if this has any effect.
I would appreciate any help for this, and instructions for what I should do.
Firefox 48+ doesn't support webdriver.Firefox().
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
caps["binary"] = "path/to/your/firefox"
browser = webdriver.Firefox(capabilities=caps)
browser.get('http://www.seleniumhq.org')
This is what I was trying
1. download geckodriver.https://github.com/mozilla/geckodriver/releases. v.0.10.0is for selenium 3(beta).
2. add PATH your geckodriver.
4. rename it to wires
5. restart shell
6. check the version
$ wires --version
7. and run above the code.

Python Selenium Firefox driver - Disable Images

Before I have used the code below, but it doesn't work anymore with firefox update.
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference('permissions.default.image', 2)
I also tried this one below, it seems good but is there a way to disable images without add-on or 3rd party tools?
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.add_extension(folder_xpi_file_saved_in + "\\quickjava-2.0.6-fx.xpi")
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Images", 2) ## Turns images off
Have you tried updating your selenium after the Firefox update?
eg :
sudo -H pip install --upgrade selenium

Python selenium webdriver get stack

I implemented below code to check selenium, but it get stuck, firefox window is not opened and nothing of error appears. print line is not executed.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")
print 'aaa'
driver.close()
I using 2.7.0 Selenium version and 44.0.2 firefox version. any idea what can be wrong here?
Your selenium is too old for the firefox 44, upgrade:
pip install --upgrade selenium

Categories

Resources