Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 当作为sudo运行时,Selenium脚本不会在Firefox中运行_Python 3.x_Selenium_Selenium Webdriver_Geckodriver - Fatal编程技术网

Python 3.x 当作为sudo运行时,Selenium脚本不会在Firefox中运行

Python 3.x 当作为sudo运行时,Selenium脚本不会在Firefox中运行,python-3.x,selenium,selenium-webdriver,geckodriver,Python 3.x,Selenium,Selenium Webdriver,Geckodriver,我有以下简单的脚本 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() 当我以普通用户的身份运行这个脚本时,python3te

我有以下简单的脚本

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()

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

selenium.common.exceptions.WebDriverException:消息:无效参数:无法终止已退出的进程


有一个需求需要脚本作为根用户执行。我应该怎么做才能合并它?

试着在无头模式下运行它

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。