簡體   English   中英

urlopen錯誤[Errno 111]連接拒絕了selenium python

[英]urlopen error [Errno 111] Connection refused for selenium python

當我嘗試從測試頁面注銷時,會出現連接拒絕錯誤。 這是我用過的命令/代碼:

driver.find_element_by_xpath("//a[@href = '/logged/pages/user/logout.php']").click()

我也嘗試過linktext或ActionChains,同樣的錯誤。 它發生在某個時間,而不是總是,任何評論?

錯誤消息:

<urlopen error [Errno 111] Connection refused>
Stacktrace

Traceback (most recent call last):
  File "/home/jenkins/run/workspace/QA_DEV_CINDY_LOGGED/LoggedSmoke/LoggedCommonFunction.py", line 158, in Logout
    link.click()
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/webelement.py", line 70, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/webelement.py", line 404, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/webdriver.py", line 193, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/remote_connection.py", line 358, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python3.3/site-packages/selenium/webdriver/remote/remote_connection.py", line 426, in _request
    resp = opener.open(request)
  File "/usr/local/lib/python3.3/urllib/request.py", line 469, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.3/urllib/request.py", line 487, in _open
    '_open', req)
  File "/usr/local/lib/python3.3/urllib/request.py", line 447, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.3/urllib/request.py", line 1274, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/local/lib/python3.3/urllib/request.py", line 1253, in do_open
    r = h.getresponse()
  File "/usr/local/lib/python3.3/http/client.py", line 1147, in getresponse
    response.begin()
  File "/usr/local/lib/python3.3/http/client.py", line 358, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.3/http/client.py", line 328, in _read_status
    raise BadStatusLine(line)
http.client.BadStatusLine: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/urllib/request.py", line 1248, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/local/lib/python3.3/http/client.py", line 1065, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python3.3/http/client.py", line 1103, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python3.3/http/client.py", line 1061, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python3.3/http/client.py", line 906, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.3/http/client.py", line 844, in send
    self.connect()
  File "/usr/local/lib/python3.3/http/client.py", line 822, in connect
    self.timeout, self.source_address)
  File "/usr/local/lib/python3.3/socket.py", line 435, in create_connection
    raise err
  File "/usr/local/lib/python3.3/socket.py", line 426, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused 

這是Selenium語言綁定和Selenium服務器之間臨時連接問題 如果您在不同的計算機上使用遠程Selenium服務器,特別是如果它通過Internet,則可能會更頻繁地發生這種情況。 例如,我們在BrowserStack或Sauce Labs使用遠程selenium服務器時看到了這種錯誤。

由於Python / Selenium綁定沒有自動重試JSON wire(JSON over HTTP)請求/命令的方法,因此您必須在代碼中處理它。 例如,如果這些是您正在執行的測試 - 解決這些錯誤的常用方法是重試失敗的測試3次,並且僅當所有3次嘗試都失敗時 - 報告測試失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM