使用geckodriver和firefox拒绝连接

使用geckodriver和firefox拒绝连接

本文介绍了Selenium Python selenium.common.exceptions.WebDriverException:消息:使用geckodriver和firefox拒绝连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having issues running my automation test scripts. When I run my script, a browser will appear but it will not type the URL and waits for 10 seconds until it throws an exception. Is there any solutions I can use so then I can get my automation test scripts to work?

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/')

规格:

推荐答案

在没有错误堆栈跟踪的情况下,配置问题很难调试.话虽如此,我在您的代码块中看不到任何重大问题.您可能需要执行一些其他步骤,如下所示:

In absence of the error stack trace configuration issues are pretty hard to debug. Having said that I don't see any major issues in your code block. You may require to perform some additional steps as follows :

  • 传递 Key executable_path 以及 Value 来引用 GeckoDriver 的绝对路径如下:

  • Pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver as follows :

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, executable_path='/path/to/geckodriver')
    driver = self.driver
    driver.get('https://www.amazon.com/')

通过您的 IDE

  • 清洁您的项目工作区重建您的项目,并且仅具有必需的依赖项.

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

    或者,您也可以尝试如下使用set_headless(headless=boolean_value):

    As an alternative you can also try to use the set_headless(headless=boolean_value) as follows :

    def setUp(self):
        binary = FirefoxBinary('/usr/bin/firefox/firefox')
        opts = FirefoxOptions()
        opts.set_headless(headless=True)
        self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts, executable_path='/path/to/geckodriver')
        driver = self.driver
        driver.get('https://www.amazon.com/')
    

    您可以在

    这篇关于Selenium Python selenium.common.exceptions.WebDriverException:消息:使用geckodriver和firefox拒绝连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-12 01:42