当网络驱动程序找不到elem时,无法建立新连接

时间:2019-06-21 10:50:44

标签: django python-3.x selenium-webdriver

当我使用WebDriverWait并且找不到符号时,它会提醒我urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fde08091f98>: Failed to establish a new connection: [Errno 111] Connection refused

这是我的代码:

  elem = WebDriverWait(driver,time_len).until(EC.presence_of_element_located((By.XPATH, xpath)))

错误:

INFO isElementExist common 2019-06-21 18:32:44,099 //*[@id="phone-state"]元素查找出错
HTTPConnectionPool(host='127.0.0.1', port=39243): Max retries exceeded with url: /session/7512e5500bbe03e5d8d6490081733642/element (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fde08091f98>: Failed to establish a new connection: [Errno 111] Connection refused'))
INFO isElementExist common 2019-06-21 18:32:44,100 traceback.format_exc():
Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 355, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/python3/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/python3/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/python3/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/python3/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/usr/local/python3/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connection.py", line 183, in connect
    conn = self._new_conn()
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fde08091f98>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/sinan_ui/comm/common.py", line 38, in isElementExist
    elem = WebDriverWait(driver,time_len).until(EC.presence_of_element_located((By.XPATH, xpath)))
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 71, in until
    value = method(self._driver)
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/support/expected_conditions.py", line 64, in __call__
    return _find_element(driver, self.locator)
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/support/expected_conditions.py", line 411, in _find_element
    return driver.find_element(*by)
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/python3/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 402, in _request
    resp = http.request(method, url, body=body, headers=headers)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/request.py", line 72, in request
    **urlopen_kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/request.py", line 150, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/poolmanager.py", line 326, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    **response_kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    **response_kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    **response_kw)
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/python3/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=39243): Max retries exceeded with url: /session/7512e5500bbe03e5d8d6490081733642/element (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fde08091f98>: Failed to establish a new connection: [Errno 111] Connection refused'))

0 个答案:

没有答案