繁体   English   中英

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

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

我正在尝试使用 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

主文件

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

要求.txt

selenium==3.141.0

这是整个项目。 我在其他项目中遇到了同样的问题,我试图在这里隔离问题。

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

我想这里的 geckodriver.log 中可能有一些有趣的信息,但我不知道在崩溃后如何访问 geckodriver.log。 我想一个选择是让 geckodriver 登录到标准输出,但我还没有找到任何方法来做到这一点。

我试过在 Python 3.6 和 Python 3.7 上运行它。 同样在 Ubuntu 18.04 上。 但我对此没有任何运气。

关于如何解决这个问题的任何想法?

解决方案由上面的 pcalkins 发布。 在 GitHub Actions 上,Firefox 必须以无头模式启动。 这有效:

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