Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python splinter拒绝Selenium远程连接_Python_Selenium_Splinter - Fatal编程技术网

使用Python splinter拒绝Selenium远程连接

使用Python splinter拒绝Selenium远程连接,python,selenium,splinter,Python,Selenium,Splinter,我正在试用splinter进行浏览器测试。不幸的是,它似乎无法连接到该网站。手动操作时,网站在浏览器中可以正常打开 我忘了什么吗?我遵循splinter文档网站上的示例 我的python代码: from splinter import Browser with Browser() as browser: browser.visit("http://some-ip") if browser.is_element_present_by_name("hour"): brow

我正在试用splinter进行浏览器测试。不幸的是,它似乎无法连接到该网站。手动操作时,网站在浏览器中可以正常打开

我忘了什么吗?我遵循splinter文档网站上的示例

我的python代码:

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
回溯(最近一次呼叫最后一次):
文件“browser test.py”,第6行,在
如果browser.is_element_present_by_name(“hour”):
文件“/usr/local/lib/python2.7/dist packages/splinter/driver/webdriver/_uinit_uuuuuuuuuuuuuuuuu.py”,第261行,在is_元素中按名称显示
返回self.is\u element\u present(self.find\u by\u name、name、wait\u time)
文件“/usr/local/lib/python2.7/dist-packages/spliter/driver/webdriver/__-init__uuuuuu.py”,第229行,在元素中
如果查找器(选择器):
文件“/usr/local/lib/python2.7/dist-packages/spliter/driver/webdriver/_uuinit_uuuuuuuu.py”,第369行,在find_by_name中
返回self.find_by(self.driver.find_elements_by_name,name)
文件“/usr/local/lib/python2.7/dist-packages/splinter/driver/webdriver/__-init__uuuuuuu.py”,第350行,在find_by中
元素=查找器(选择器)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第314行,按名称查找元素
返回self.find_元素(by=by.NAME,value=NAME)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第677行,在find_元素中
{'using':by'value':value})['value']
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第171行,在execute中
响应=self.command\u executor.execute(driver\u command,params)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/remote_connection.py”,第349行,在execute中
返回self.\u请求(命令信息[0],url,正文=数据)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/remote\u connection.py”,第379行,在请求中
self.\u conn.request(方法、解析的\u url.path、正文、标题)
文件“/usr/lib/python2.7/httplib.py”,第973行,在请求中
self.\u发送请求(方法、url、正文、标题)
文件“/usr/lib/python2.7/httplib.py”,第1007行,在发送请求中
self.endheaders(主体)
文件“/usr/lib/python2.7/httplib.py”,第969行,在endheaders中
自发送输出(消息体)
文件“/usr/lib/python2.7/httplib.py”,第829行,在“发送”输出中
self.send(msg)
文件“/usr/lib/python2.7/httplib.py”,第791行,在send中
self.connect()
文件“/usr/lib/python2.7/httplib.py”,第772行,在connect中
self.timeout,self.source\u地址)
文件“/usr/lib/python2.7/socket.py”,第571行,在create_connection中
提出错误
socket.error:[Errno 111]连接被拒绝

结果是一个缩进错误-愚蠢的我。我这样回答是为了防止其他人犯同样的错误

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"

是否可以包含导致问题的特定URL?错误消息是一种通用消息;它只说明客户端无法建立连接,因此需要一些额外的信息来解决这个问题;不幸的是,我不能马上说什么额外的信息将是关键。url是一个本地网络IP地址。我在一个虚拟ubuntu上运行python,我还检查了该网站是否可以从虚拟机中的浏览器访问,并且运行良好。这可能是一个浏览器错误的症状-有时浏览器(自动)更新会破坏Selenium兼容性。我建议在最终裁决之前尝试不同的浏览器和phantomjs驱动程序。我会记住:)