S.A.
S.A.

Reputation: 109

Selenium with webdriver.Firefox() crashes in GitHub Actions

I'm trying to run selenium using GitHub Actions but selenium is crashing:

Traceback (most recent call last):
File "main.py", line 2, in <module>
webdriver.Firefox()
File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

main.py

from selenium import webdriver
webdriver.Firefox()

.github/workflows/test.yml

name: Python application

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.8.2
      uses: actions/setup-python@v2
      with:
        python-version: 3.8.2
    - name: geckodriver/firefox
      run: |
        echo "geckodriver/firefox"
        which geckodriver
        geckodriver --version
        which firefox
        firefox --version
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8 pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test selenium
      run: |
        python main.py

requirements.txt

selenium==3.141.0

This is the entire project. I'm having the same problem in other projects and I'm trying to isolate the problem here.

The geckodriver/firefox step prints

geckodriver/firefox
/usr/bin/geckodriver
geckodriver 0.27.0 (7b8c4f32cdde 2020-07-28 18:16 +0000)

The source code of this program is available from
testing/geckodriver in https://hg.mozilla.org/mozilla-central.

This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
/usr/bin/firefox
Mozilla Firefox 82.0

I guess there could be some interesting information in geckodriver.log here, but I don't know how to access the geckodriver.log after this is crashing. I guess an option would be to make geckodriver log to stdout, but I haven't found any way of doing this.

I've tried running this on Python 3.6 and Python 3.7. Also on Ubuntu 18.04. But I haven't had any luck with this.

Any ideas on how to solve this?

Upvotes: 2

Views: 1339

Answers (1)

S.A.
S.A.

Reputation: 109

The solution was posted by pcalkins above. On GitHub Actions Firefox must be launched in headless mode. This works:

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.headless = True
webdriver.Firefox(options=options)

Upvotes: 4

Related Questions