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

0 like 0 dislike
506 views
by The go-to Tester (218 points)

I am running test using selenium webdriver in Python language. My code is-:

import unittest
import os
from selenium import webdriver


class TestTwo(unittest.TestCase):

    def setUp(self):
        gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
        self.driver = webdriver.Firefox(executable_path=gecko+'.exe')

    def test_url(self):
        self.driver.get("http://www.seleniumhq.org") 
        assert "Selenium" in driver.title

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

I am getting error -:

Traceback (most recent call last):
  File "E:\Python Workspace\exampletest.py", line 10, in setUp
    self.driver = webdriver.Firefox(executable_path=gecko+'.exe')
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 150, in __init__
    keep_alive=True)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'firefox_binary' capability provided, and no binary flag set on the command line

1 Answer

0 like 0 dislike
by
selected by
 
Best answer

You will have to set PATH environment variable to set gekoriver. You have to append path to the directory containing gekodriver binary to your PATH environment variable value string.

Eg.

In Unix based system,

export PATH = $PATH:/path/to/directory/of/gekodriver/executable/

in windows based system,

setx path "%path%;c:\path\to\gekodriver\dir"

And, in webdriver.Firefox construction, do not pass anything. Provided that your Firefox is installed at the default location.

So, your code should look like below.

def setUp(self):
        //gecko = os.path.normpath(os.path.join(os.path.dirname(__file__), 'geckodriver'))
        //self.driver = webdriver.Firefox(executable_path=gecko+'.exe')

        self.driver = webdriver.Firefox()

Hope that helps!


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...