简体   繁体   English

带有 webdriver.Firefox() 的 Selenium 在 GitHub 操作中崩溃

[英]Selenium with webdriver.Firefox() crashes in GitHub Actions

I'm trying to run selenium using GitHub Actions but selenium is crashing:我正在尝试使用 GitHub Actions 运行 selenium,但 selenium 崩溃了:

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 .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要求.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 步骤打印

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.我想这里的 geckodriver.log 中可能有一些有趣的信息,但我不知道在崩溃后如何访问 geckodriver.log。 I guess an option would be to make geckodriver log to stdout, but I haven't found any way of doing this.我想一个选择是让 geckodriver 登录到标准输出,但我还没有找到任何方法来做到这一点。

I've tried running this on Python 3.6 and Python 3.7.我试过在 Python 3.6 和 Python 3.7 上运行它。 Also on Ubuntu 18.04.同样在 Ubuntu 18.04 上。 But I haven't had any luck with this.但我对此没有任何运气。

Any ideas on how to solve this?关于如何解决这个问题的任何想法?

The solution was posted by pcalkins above.解决方案由上面的 pcalkins 发布。 On GitHub Actions Firefox must be launched in headless mode.在 GitHub Actions 上,Firefox 必须以无头模式启动。 This works:这有效:

from selenium import webdriver

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM