Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
7.8k views
by

I am getting below error with my selenium script.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
driver.maximize_window()
driver.get("http://mayurshah.in")
assert "" in driver.title
elem = driver.find_element_by_css_selector("li.qa-nav-main-item:nth-child(5) > a:nth-child(1)")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "Nothing Found" in driver.page_source
driver.close()
 

Command

C:\Users\mail_xe7zkvh\Documents>py chennaipydemo.py

Error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python35-32\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 "chennaipydemo.py", line 6, in <module>
    driver = webdriver.Firefox(firefox_binary=binary)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
    self.service.start()
  File "C:\Program Files (x86)\Python35-32\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.

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00A0EBD0>>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
    self.stop()
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

2 Answers

1 like 0 dislike
by The go-to Tester (181 points)

Its looking for geckodriver.

Download geckodriver from below location and add it to your PATH veriable.

https://github.com/mozilla/geckodriver/releases

Exit existing command line and reopen the same. This should help you.

0 like 0 dislike
by The go-to Tester (222 points)
by Expert (748 points)
Download gecko driver http://seleniumhq.org
and put these code as like::;;
     System.setProperty("webdriver.firefox.marionette","E://Users//Bharat Varshney//workspace//drivers//geckodriver.exe");
        driver = new FirefoxDriver();
by Master (1.2k points)
Thank you Bharat, You can add this as an answer as well.
...