Selenium Pythonselenium.common.exceptions.WebDriverException:消息:使用geckodriver和firefox拒绝连接

发布于 2021-01-29 17:58:39

我在运行自动化测试脚本时遇到问题。当我运行脚本时,将出现一个浏览器,但它不会键入URL,并等待10秒钟,直到引发异常。有什么可以使用的解决方案,以便可以使自动化测试脚本正常工作吗?

Geckodriver.log

1523997052492   geckodriver INFO    geckodriver 0.20.1
1523997052531   geckodriver INFO    Listening on 127.0.0.1:37807
1523997052592   mozrunner::runner   INFO    Running command: "/usr/bin/firefox/firefox" "-marionette" "--headless" "-profile" "/tmp/rust_mozprofile.PU1cngaAJ5Tg"
1523997054831   Marionette  INFO    Listening on port 2828

堆栈跟踪

Error
Traceback (most recent call last):
File 
"/home/kavin/PycharmProjects/untitled/Testing/purchaseAmazonItems.py", line 13, in setUp
self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 162, in __init__
keep_alive=True)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

代码

def setUp(self):
    binary = FirefoxBinary('/usr/bin/firefox/firefox')
    opts = FirefoxOptions()
    opts.add_argument("--headless")
    self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts)
    driver = self.driver
    driver.get('https://www.amazon.com/')

规格

Ubuntu 16.04
geckodriver 0.20.1
firefox 59.0.2 + build1-0ubuntu0.16.04.3
Python 3.6
Pycharm 2016.3
硒3.11.0

关注者
0
被浏览
164
1 个回答
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看