braincrash
braincrash

Reputation: 57

error: [Errno 111] Connection refused - Python, Selenium

I am learning to use Selenium. So far, I succeeded in getting it to work. So, now I wanted to record navigation sequences using Selenium IDE, export them to python and run them.

This is the code I used.

from selenium import selenium
import unittest, time, re
#from pyvirtualdisplay import Display

class rc(unittest.TestCase):
def setUp(self):
    self.verificationErrors = []
    #self.display = Display(visible=0, size=(1024, 768))
    #self.display.start()
    self.selenium = selenium("localhost", 4444, "*chrome", "http://www.some-website.in")
    self.selenium.start()

def test_rc(self):
    sel = self.selenium
    sel.click("link=Careers")
    response = sel.get_title()
    print response

def tearDown(self):
    self.selenium.stop()
    self.assertEqual([], self.verificationErrors)
    #self.display.stop()

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

The commented lines are manually added and were tried in case they worked (as they did in the previous basic example in which I just wanted selenium to work and resolve dependencies).

On running this auto-generated python code, I get:

File "mytest_test.py", line 34, in setUp
  self.selenium.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 202, in start
  result = self.get_string("getNewBrowserSession", start_args)
File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 237, in get_string
  result = self.do_command(verb, args)
File "/usr/local/lib/python2.7/dist-packages/selenium/selenium.py", line 226, in do_command
  conn.request("POST", "/selenium-server/driver/", body, headers)
File "/usr/lib/python2.7/httplib.py", line 973, in request
  self._send_request(method, url, body, headers)
File "/usr/lib/python2.7/httplib.py", line 1007, in _send_request
  self.endheaders(body)
File "/usr/lib/python2.7/httplib.py", line 969, in endheaders
  self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 829, in _send_output
  self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 791, in send
  self.connect()
File "/usr/lib/python2.7/httplib.py", line 772, in connect
  self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
  raise err
error: [Errno 111] Connection refused

Help?

Upvotes: 3

Views: 9822

Answers (3)

Yogesh
Yogesh

Reputation: 1

When you face such an issue, check your geckodriver setup.

When you open a browser, your marionette driver code should be commented like this: #cap['marionette'] = True.

Don't enable the marionette driver for Linux.

Upvotes: 0

pymen
pymen

Reputation: 6539

In my case the problem was with incompatible version of Chrome and chromedriver

check following commands in your terminal:

cd <<your test folder>>
which chromedriver
chromedriver --version  

and compare the version with the latest version of chromedriver: https://sites.google.com/a/chromium.org/chromedriver/

Upvotes: 1

Sadik Ali
Sadik Ali

Reputation: 1195

You converted test script for selenium RC, so make sure that selenium RC server is running at your machine before executing test script.

User below command to run selenium server: open command prompt and go to downloaded selenium server jar file and run command

java -jar selenium-server-standalone-2.47.1.jar

Upvotes: 1

Related Questions