2

I'm trying out splinter for browser testing. Unfortunately it seems like it can't connect to the website. The website opens fine in the browser when done manually.

Have I forgotten something? I followed the examples on the splinter documentation website.

My python code:

from splinter import Browser

with Browser() as browser:
    browser.visit("http://some-ip")

if browser.is_element_present_by_name("hour"):    
    browser.find_by_name("hour").fill("13")
else:
    print "No hour element"

Error message when running the script:

Traceback (most recent call last):
  File "browser-test.py", line 6, in <module>
    if browser.is_element_present_by_name("hour"):    
  File "/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/__init__.py", line 261, in is_element_present_by_name
    return self.is_element_present(self.find_by_name, name, wait_time)
  File "/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/__init__.py", line 229, in is_element_present
    if finder(selector):
  File "/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/__init__.py", line 369, in find_by_name
    return self.find_by(self.driver.find_elements_by_name, name)
  File "/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/__init__.py", line 350, in find_by
    elements = finder(selector)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 314, in find_elements_by_name
    return self.find_elements(by=By.NAME, value=name)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 677, in find_elements
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 171, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 349, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 379, in _request
    self._conn.request(method, parsed_url.path, 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
socket.error: [Errno 111] Connection refused
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
KMK
  • 1,439
  • 5
  • 21
  • 39
  • Can you include a specific URL that causes the problem? The error message is kind of generic; it doesn't really say anything more than that the client was unable to make a connection, so it's going to take some additional information to figure this out; unfortunately I couldn't say offhand _what_ additional information will be the key. – David Z Apr 21 '15 at 09:54
  • The url is a local network IP address. I'm running python on a virtual ubuntu, and I also checked that the website is acccessible from a browser in the virtual machine and it works fine. – KMK Apr 21 '15 at 10:36
  • This might be a sympton of a browser bug - sometimes browser (auto) updates break Selenium compatibility. I suggest try out different browsers and phantomjs driver before the final verdict . – Mikko Ohtamaa Apr 21 '15 at 10:57

1 Answers1

1

Turned out to be an indentation error - stupid me. I made this answer in case anyone else makes the same mistake.

from splinter import Browser

with Browser() as browser:
    browser.visit("http://some-ip")

    if browser.is_element_present_by_name("hour"):    
        browser.find_by_name("hour").fill("13")
    else:
        print "No hour element"
KMK
  • 1,439
  • 5
  • 21
  • 39