Selenium Python selenium.common.exceptions.WebDriverException: Message: connection refused using geckodriver and firefox

前端 未结 2 1261
迷失自我
迷失自我 2020-12-07 02:54

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 e

相关标签:
2条回答
  • 2020-12-07 03:26

    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 :

    • 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/')
      
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

    • Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
    • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Take a System Reboot.
    • Execute your @Test.
    • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

    Alternative

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

    Here you can find a detailed discussion on How to make firefox headless programatically in Selenium with python?

    0 讨论(0)
  • 2020-12-07 03:37

    These two commands both start a webdriver on the same port. The second one causes the error because the port is already in use:

    self.driver = webdriver.Firefox(firefox_binary=binary)
    browser = webdriver.Firefox(firefox_options=opts)
    

    To correct this, set the options before initializing the driver (in the first command).

    self.driver = webdriver.Firefox(firefox_binary=binary, firefox_options=opts)
    
    0 讨论(0)
提交回复
热议问题