我正准备开发一些selenium测试(使用无头firefox运行),当我通过此命令获取webdriver时,server.log
中出现以下错误:
driver = webdriver.Firefox(firefox_profile = profile, log_path = logfile)
这是错误:
1518520162032 geckodriver::marionette INFO Starting browser /usr/bin/firefox with args ["-marionette"]
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :1137
我不记得有什么改变。它之前只运行了一百次。如何解决这个错误???
答案 0 :(得分:0)
错误说明了一切:
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :1137
这实质上意味着未正确设置DISPLAY
属性。
在.bashrc中添加以下配置:
export DISPLAY=:0
Unntu 16.04上的Gnome,正确的值是 DISPLAY=:1
(不是DISPLAY=:0
)
问题可能是由于/ etc / sudoers中的env_keep变量。所以一个永久的解决方案是使用gedit或使用sudo visudo在/ etc / sudoers的末尾添加以下行:
Defaults env_keep+="DISPLAY"
注意:有关详细讨论,请参阅Failed to connect to Mir: Failed to connect to server socket: No such file or directory