Error: no DISPLAY environment variable specified

Error: no DISPLAY environment variable specified

我已经设置了一个 Selenium Grid,在 Ubuntu 服务器中有一个集线器,在 Ubuntu 桌面中有一个节点。在 Node 机器上安装 Geckodriver 和 Firefox。并使用以下 python 代码。

from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions

options = webdriver.FirefoxOptions()
driver = webdriver.Remote(
    command_executor='http://192.168.56.7:4444/wd/hub',
    options=options
)

但是出现错误错误:节点机器上没有指定 DISPLAY 环境变量

添加后工作正常

options.add_argument('--headless')

不想 运行 它处于无头模式。

在此先感谢大家。

请尝试设置环境变量DISPLAY

您的问题与 Selenium Error: no display specified

有点重复

查看@peter-quan提供的link。如果你是 运行 来自 SSH 的节点连接,你将面临这个问题。

除此之外,我正在添加帮助我解决问题的命令。

sudo apt-get install xvfb
touch ~/.Xauthority
xauth generate :0 . trusted
xauth add ${HOST}:0 . $(xxd -l 16 -p /dev/urandom)
xauth list
export DISPLAY=:0
java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://[HUB-IP]:4444/grid/register/