driver.quit和driver.close不可以同时使用

driver.quit和driver.close不可以同时使用

报错信息如下

Error

Traceback (most recent call last):

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connection.py", line 170, in _new_conn

(self._dns_host, self.port), self.timeout, **extra_kw

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\util\connection.py", line 96, in create_connection

raise err

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\util\connection.py", line 86, in create_connection

sock.connect(sa)

ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen

chunked=chunked,

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connectionpool.py", line 394, in _make_request

conn.request(method, url, **httplib_request_kw)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connection.py", line 234, in request

super(HTTPConnection, self).request(method, url, body=body, headers=headers)

File "E:\python37\lib\http\client.py", line 1262, in request

self._send_request(method, url, body, headers, encode_chunked)

File "E:\python37\lib\http\client.py", line 1308, in _send_request

self.endheaders(body, encode_chunked=encode_chunked)

File "E:\python37\lib\http\client.py", line 1257, in endheaders

self._send_output(message_body, encode_chunked=encode_chunked)

File "E:\python37\lib\http\client.py", line 1028, in _send_output

self.send(msg)

File "E:\python37\lib\http\client.py", line 968, in send

self.connect()

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connection.py", line 200, in connect

conn = self._new_conn()

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connection.py", line 182, in _new_conn

self, "Failed to establish a new connection: %s" % e

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x0000019AEE9025C8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "E:\python37\lib\unittest\case.py", line 59, in testPartExecutor

yield

File "E:\python37\lib\unittest\case.py", line 631, in run

self.tearDown()

File "E:\PYPJ\FENSEN\testcase\test_FEISEN_02.py", line 53, in tearDown

self.driver.close()

File "E:\PYPJ\FENSEN\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 688, in close

self.execute(Command.CLOSE)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 319, in execute

response = self.command_executor.execute(driver_command, params)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 374, in execute

return self._request(command_info[0], url, body=data)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 397, in _request

resp = self._conn.request(method, url, body=body, headers=headers)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\request.py", line 75, in request

method, url, fields=fields, headers=headers, **urlopen_kw

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\request.py", line 96, in request_encode_url

return self.urlopen(method, url, **extra_kw)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\poolmanager.py", line 375, in urlopen

response = conn.urlopen(method, u.request_uri, **kw)

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connectionpool.py", line 796, in urlopen

**response_kw

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connectionpool.py", line 796, in urlopen

**response_kw

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connectionpool.py", line 796, in urlopen

**response_kw

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen

method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]

File "E:\PYPJ\FENSEN\venv\lib\site-packages\urllib3\util\retry.py", line 574, in increment

raise MaxRetryError(_pool, url, error or ResponseError(cause))

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=1045): Max retries exceeded with url: /session/1b3745aaa379ba3703bfdf18369859a9/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000019AEE9025C8>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

因为我按照以前的写法,在用例的teardown方法的结尾写了

driver.quit()

driver.close()

但是如果我把close那行去掉或者quit去掉,只留其中一个,就可以正常运行不会报错,有没有人知道是什么原因呢?在以前的项目中这样的写法是不会报错的。


回答:

driver.quit()

  • 关闭与该 WebDriver 会话关联的所有窗口和选项卡
  • 关闭浏览器进程
  • 关闭后台驱动进程

driver.close()

  • 关闭当前窗口和选项卡

参考 browser_manipulation

以上是 driver.quit和driver.close不可以同时使用 的全部内容, 来源链接: utcz.com/p/938025.html

回到顶部