0 votes
1 view
in Devops and Agile by (24.5k points)

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?

1 Answer

0 votes
by (62.4k points)

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable has to be in PATH.

First of all, you may download the latest executable geckodriver from here to run the latest firefox using selenium

Actually, The selenium client bindings try and find the geckodriver executable from the system PATH. You will add the directory containing the executable to the system path.

On UNIX systems you'll do the following to append it to your system’s search path if you’re employing a bash-compatible shell:

export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step

On Windows, you may update the path system variable to feature the full directory path to the executable geckodriver manually or by using the command-line interface(don't forget to restart your system after adding executable geckodriver into system PATH). The principle is the same as on Unix.

Now you'll run your code same as you are doing as below:-

from selenium import webdriver

browser = webdriver.Firefox()

selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in the default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

Exception clearly states you have installed firefox some other location whereas selenium is attempting to {find|to seek out|to search out} firefox and launch from default location but it could not find. You need to provide explicitly firefox installed binary location to launch firefox as below:- 

from selenium import webdriver

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('path/to/installed firefox binary')

browser = webdriver.Firefox(firefox_binary=binary)

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...