WebDriverException: Message: invalid argument: can't kill an exited process error with Selenium GeckoDriver and Firefox in Google Colab on Ubuntu
Asked Answered
O

1

1

In a previous post (enter link description here) the following code (by DebanjanB)

# install firefox, geckodriver, and selenium
!apt-get update
!pip install selenium
!apt install firefox-geckodriver
!cp /usr/lib/geckodriver /usr/bin
!cp /usr/lib/firefox /usr/bin

from selenium import webdriver

binary = '/usr/bin/firefox'
options = webdriver.FirefoxOptions()
options.binary = binary
options.add_argument('start-maximized')
options.add_argument('--headless')
browser = webdriver.Firefox(firefox_options=options, executable_path='/usr/bin/geckodriver')
browser.get('http://google.com/')

which is correct, caused a version problem. I'm not an expert in Ubuntu.

I use Google Colaboratory, Python3.6, Selenium3.14.

WebDriverException                        Traceback (most recent call last)
<ipython-input-2-f7828de5f77c> in <module>()
      4 options.add_argument('start-maximized')
      5 options.add_argument('--headless')
----> 6 browser = webdriver.Firefox(options=options, executable_path='/usr/bin/geckodriver')
      7 driver.get("https://www.google.com")
      8 print(driver.page_source)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, options, service_log_path, firefox_options, service_args, desired_capabilities, log_path, keep_alive)
    172                 command_executor=executor,
    173                 desired_capabilities=capabilities,
--> 174                 keep_alive=True)
    175 
    176         # Selenium remote

/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py in __init__(self, command_executor, desired_capabilities, browser_profile, proxy, keep_alive, file_detector, options)
    155             warnings.warn("Please use FirefoxOptions to set browser profile",
    156                           DeprecationWarning, stacklevel=2)
--> 157         self.start_session(capabilities, browser_profile)
    158         self._switch_to = SwitchTo(self)
    159         self._mobile = Mobile(self)

/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py in start_session(self, capabilities, browser_profile)
    250         parameters = {"capabilities": w3c_caps,
    251                       "desiredCapabilities": capabilities}
--> 252         response = self.execute(Command.NEW_SESSION, parameters)
    253         if 'sessionId' not in response:
    254             response = response['value']

/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py in execute(self, driver_command, params)
    319         response = self.command_executor.execute(driver_command, params)
    320         if response:
--> 321             self.error_handler.check_response(response)
    322             response['value'] = self._unwrap_value(
    323                 response.get('value', None))

/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    240                 alert_text = value['alert'].get('text')
    241             raise exception_class(message, screen, stacktrace, alert_text)
--> 242         raise exception_class(message, screen, stacktrace)
    243 
    244     def _value_or_default(self, obj, key, default):

WebDriverException: Message: invalid argument: can't kill an exited process

I searched the internet and only found that this is a version conflict between Firefox and Geckodriver. But nobody gives the solution how to choose the compatible versions. This is my problem. Any help is appreciated.

Opus answered 20/8, 2019 at 19:46 Comment(9)
Can you change firefox_options=options to options=options and retest once again?Exteroceptor
I did earlier, and the same error message is produced. See line 6 with ---->Opus
Can you drop the --headless option and let me know the observation?Exteroceptor
I dropped --headless , and the error message is the same.Opus
One last try, can you replace binary = '/usr/bin/firefox' with binary = r'/usr/bin/firefox' and executable_path='/usr/bin/geckodriver' with executable_path = r'/usr/bin/geckodriver'Exteroceptor
Unfortunately the letter r does not help. Is it possible to replace !apt install firefox-geckodriver with other installing method? Maybe instead of bionic using something else? My knowledge about Ubuntu is very little.Opus
Can you checkout the steps mentioned in the answer within this discussion please?Exteroceptor
Thanks for the link of the other discussion.Opus
I tried it on Google Colaboratory same issue . Google chrome working fine . It has to do with firefox rather than geckodriver Even ..>firefox -v | more . Command shows errorMaremma
A
0

Following code:

# install firefox, geckodriver, and selenium
!apt-get update
!pip install selenium
!apt install firefox

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

options = webdriver.FirefoxOptions()
options.add_argument('start-maximized')
options.add_argument('--headless')

browser = webdriver.Firefox(options=options)
try:
  browser.get('http://google.com/')
  print(browser.title)
except Exception as e:
  browser.quit()
  raise e

works just fine as on Google-Collab (as per 2024-01-08 update)

Note: options argument, binary & firefox installation had to be revised

Alcantar answered 12/1 at 7:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.