I'm new to programming and started with Python
about 2 months ago and am going over Sweigart's Automate the Boring Stuff with Python text. I'm using IDLE and already installed the selenium module and the Firefox browser.
Whenever I tried to run the webdriver function, I get this:
from selenium import webdriver
browser = webdriver.Firefox()
Exception :-
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Python\Python35\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Python\Python35\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
browser = webdriver.Firefox()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
I think I need to set the path for geckodriver
but not sure how, so can anyone tell me how would I do this?
On macOS with Homebrew already installed you can simply run the Terminal command
Because homebrew already did extend the
PATH
there's no need to modify any startup scripts.On Raspberry Pi I had to create from ARM driver and set the geckodriver and log path in:
sudo nano /usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py
To set up geckodriver for Selenium Python:
It needs to set geckodriver path with FirefoxDriver as below code:
Download geckodriver for your suitable OS (from https://github.com/mozilla/geckodriver/releases) -> Extract it in a folder of your choice -> Set the path correctly as mentioned above
I'm using Python 3.6.2 and Selenium WebDriver 3.4.3 in Windows 10.
Another way to set up geckodriver:
i) Simply paste the geckodriver.exe under /Python/Scripts/ (In my case the folder was: C:\Python36\Scripts)
ii) Now write the simple code as below:
Some additional input/clarification for future readers of this thread:
The following suffices as a resolution for Windows 7, Python 3.6, selenium 3.11:
@dsalaj's note in this thread earlier for Unix is applicable to Windows as well; tinkering with the PATH env. variable at the Windows level and restart of the Windows system can be avoided.
(1) Download geckodriver (as described in this thread earlier) and place the (unzipped) geckdriver.exe at X:\Folder\of\your\choice
(2) Python code sample:
Notes: (1) It may take about 10 seconds for the above code to open up the Firefox browser for the specified url.
(2) The python console would show the following error if there's no server already running at the specified url or serving a page with the title containing the string 'Django': selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=connectionFailure&u=http%3A//localhost%3A8000/&c=UTF-8&f=regular&d=Firefox%20can%E2%80%9
This solved it for me.
The easiest way for windows!
I just downloaded the latest version geckodriver (I have win10) from here and added that geckodriver.exe file in python directory
C:\Users\my.name
(which already in PATH) It worked for me!