user3503078
user3503078

Reputation: 45

Python - Webdriver command does not trigger

I have created the following Python - when I execute it I receive an error. The apparent errant line is in italics

from selenium import webdriver
import unittest
import sys

class ExampleTestCase(unittest.TestCase):

    def setUp(self):
        * Errant line below
        self.__driver = webdriver.Remote(desired_capabilities={
            "browserName": "firefox",
            "platform": "Windows",*
        })
        print("Got this far")

    def test_example(self):

        self.__driver.get("http://www.google.com")
        self.__assertEqual(self.driver.title, "Google")

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

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

The error is

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Can anyone suggest what the problem might be? I am using Python 3.4 and

Upvotes: 0

Views: 575

Answers (1)

Louis
Louis

Reputation: 151391

Your code is trying to invoke a remote instance of Selenium, which is fine only if there is a remote server able to respond to your request. If you do not specify an address (which you don't) then it is going to try connecting on the local machine. If what want to do is only start Firefox on your local machine, then you can do this:

from selenium import webdriver
import unittest
import sys

class ExampleTestCase(unittest.TestCase):

    def setUp(self):
        self.__driver = webdriver.Firefox()
        print("Got this far")

    def test_example(self):

        self.__driver.get("http://www.google.com")
        self.assertEqual(self.__driver.title, "Google")

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

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

The code above runs fine.

Upvotes: 1

Related Questions