簡體   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