我正要开发一些selenium测试(使用无头火狐运行),这时server.log中出现了以下错误,这时我正准备通过下面的命令获得webdriver:
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我不记得有什么改变。它以前起过上百次的作用。如何纠正这个错误?
发布于 2018-02-13 11:44:10
这个错误说明了一切:
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在Ubuntu16.04上的Gnome,正确的值是DISPLAY=:1 (不是DISPLAY=:0)
这个问题可能是由于/etc/sudoers中的env_keep变量造成的。因此,一个永久的解决方案是使用gedit或sudoers在/etc/sudoers末尾添加以下行:
Defaults env_keep+="DISPLAY"https://stackoverflow.com/questions/48765488
复制相似问题