网址正在Chrome中启动,但在Firefox中却出现错误

时间:2018-10-03 08:04:55

标签: python-3.x selenium firefox

当我尝试在chrome中启动URL时,它可以正常工作,但是当我尝试使用Firefox相同的URL时,却出现了一些错误,我不知道为什么,它表明我有一些连接错误并且拒绝了连接。 我写的代码

    def test_setUp(self):
    browser = 'f'
    if browser == 'f':
        self.driver = webdriver.Firefox(executable_path="/home/manoj/PycharmProjects/InvitedModel/geckodriver")
        print("Run started at : " + str(datetime.datetime.now()))
        print("FireFox environment Set up")
        print("---------------------------------------------------------------------------------------------")
        self.driver.implicitly_wait(20)
        self.driver.quit()
    else:
        self.driver = webdriver.Chrome('/home/manoj/Downloads/chromedriver_linux64/chromedriver')
        print("Run started at : " + str(datetime.datetime.now()))
        print("Chrome environment Set Up")
        print("---------------------------------------------------------------------------------------------")
        self.driver.implicitly_wait(20)

    self.driver.set_window_size(1920, 1080, self.driver.window_handles[0])
    self.driver.get("https://forum.smartron.com/")

我还安装了适当的壁虎驱动程序 FireFox 61.0.1版

错误:

Error
Traceback (most recent call last):
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/util/connection.py", line 79, in create_connection
raise err
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/util/connection.py", line 69, 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 "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connection.py", line 196, in connect
conn = self._new_conn()
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fbe29f86588>: 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 "/usr/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/lib/python3.6/unittest/case.py", line 601, in run
self.setUp()
File "/home/manoj/PycharmProjects/InvitedModel/TestBase/Environment.py", line 27, in setUp
self.driver.set_window_size(1920, 1080, self.driver.window_handles[0])
File "/home/manoj/newenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 723, in window_handles
return self.execute(Command.W3C_GET_WINDOW_HANDLES)['value']
File "/home/manoj/newenv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 318, in execute
response = self.command_executor.execute(driver_command, params)
File "/home/manoj/newenv/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 375, in execute
return self._request(command_info[0], url, body=data)
File "/home/manoj/newenv/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/request.py", line 68, in request
**urlopen_kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/request.py", line 89, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/poolmanager.py", line 322, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 667, in urlopen
**response_kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 667, in urlopen
**response_kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 667, in urlopen
**response_kw)
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/manoj/newenv/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=37043): Max retries exceeded with url: /session/affe97e5-78d3-4132-82a4-e5f43dae1604/window/handles (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fbe29f86588>: Failed to establish a new connection: [Errno 111] Connection refused',))

1 个答案:

答案 0 :(得分:1)

问题- Juan Pedro - Miguel - Joseph - Francisco 所在-您首先退出浏览器实例,然后尝试调整其大小。

- JP - Miguel - Joseph - Francisco 移动到脚本末尾。