Selenium远程连接拒绝使用Python碎片



我正在尝试使用splinter进行浏览器测试。不幸的是,它似乎无法连接到网站。手动完成后,网站在浏览器中打开正常。

我忘记了什么吗?我遵循了分裂文档网站上的示例。

我的蟒蛇代码:

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"

运行脚本时出现错误消息:

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
原来

是一个缩进错误 - 愚蠢的我。我做了这个答案,以防其他人犯同样的错误。

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"

相关内容

  • 没有找到相关文章

最新更新