2015-04-21 44 views
2

我試着分裂瀏覽器測試。不幸的是,它似乎無法連接到網站。手動完成後,該網站在瀏覽器中打開。Selenium遠程連接拒絕使用Python分裂

我忘記了什麼嗎?我遵循分裂文檔網站上的示例。

我的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 
+0

您能否包含導致問題的特定URL?錯誤信息是一種通用的;除了客戶端無法建立連接之外,它並沒有提到任何其他信息,所以需要一些額外的信息來解決這個問題。不幸的是,我不能說現在 - 什麼額外的信息將是關鍵。 –

+0

該網址是本地網絡IP地址。我在一個虛擬ubuntu上運行python,並且我也檢查過該網站是否可以從虛擬機中的瀏覽器訪問,並且工作正常。 – KMK

+0

這可能是一個瀏覽器錯誤的症狀 - 有時瀏覽器(自動)更新會破壞Selenium兼容性。我建議在最終裁決之前嘗試不同的瀏覽器和phantomjs驅動程序。 –

回答

1

原來是一個壓痕錯誤 - 愚蠢的我。如果有其他人犯了同樣的錯誤,我做出了這個答案。

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"