【问题标题】:Selenium script does not run in Firefox when run as sudo [duplicate]以 sudo 运行时,Selenium 脚本不会在 Firefox 中运行 [重复]
【发布时间】:2020-12-25 04:01:31
【问题描述】:

我有以下简单的脚本。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# Create a new instance of the Firefox driver
browser = webdriver.Firefox()

browser.get('https://www.google.com')

browser.quit()

当我以python3 test.py 的身份使用普通用户运行此脚本时,它会正确执行。但是当我以 root 用户 sudo python3 test.py 运行此脚本时,它会退出并出现以下错误:

selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

有一个要求需要以 root 用户身份执行脚本。我应该怎么做才能合并它?

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver geckodriver


    【解决方案1】:

    尝试在无头模式下运行它

    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    options = Options()
    options.headless = True
    browser = webdriver.Firefox(options=options)
    browser.get('https://www.google.com')
    browser.quit()
    

    【讨论】:

    • 嗨 Karthik,我不想在无头模式下运行它。我特别想看看 GUI。
    猜你喜欢
    • 1970-01-01
    • 2016-10-11
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 2015-08-13
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多