Hari
Hari

Reputation: 75

error while exeutiing Selenium Python automation script

I just copied selenium script from web and trying to learn selenium python automation. Here is the script

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.facebook.com")

While running I got following error

Traceback (most recent call last):
  File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, 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 "C:\Users\hpatel\python\PythonLearn\src\Example1.py", line 8, in <module>
    driver = webdriver.Firefox()
  File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
    self.service.start()
  File "C:\Users\hpatel\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

What is the issue? I copied geckodriver file to c drive and define the path too.

Upvotes: 0

Views: 271

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

Just replace this line :

driver = webdriver.Firefox()  

To:

driver = webdriver.Firefox(executable_path = r'C:/Users/user***/Downloads/geckodriver-v0.20.1-win64/geckodriver.exe')

Upvotes: 2

Related Questions