我在EC2实例上。所以没有GUI。
$pip install selenium $sudo apt-get install firefox XVFB
然后我这样做:
$ Xvfb:1轻01024年x768x242> &1> / dev / null & $ =显示:1java jar selenium-server-standalone -2.0b3.jar 05:08:31.227Java: Sun Microsystems Inc.。19.0-b09 05:08:31.229INFO -操作系统:Linux2.6.32-305ec2 i386 05:08:31.233信息- v2.0(b3),与核心v2.0(b3) 05:08:32.121INFO - RemoteWebDriver实例应该连接到:http://127.0.0.1:4444/ wd / 05:08中心:32.122INFO -版本Jetty/5.1以下方式05:08:32.123启动HttpContext[/selenium-server/driver,/selenium-server/driver] 05:08:32.124启动HttpContext[/selenium-server,/selenium-server] 05:08:32.124启动HttpContext[/,/] 05:08:32.291信息——开始(电子邮件保护)05:08:32.292启动HttpContext[/wd,/wd] 05:08:32.295INFO -启动SocketListener on0.0.0.0:444405:08:32.295信息——开始(电子邮件保护)
很好,现在一切都正常了,对吧?
当我运行我的代码:
从硒进口webdriver从selenium.common.exceptions进口NoSuchElementException从selenium.webdriver.common.keys进口webdriver.Firefox()“http://www.yahoo.com”)
我得到了这个:
错误:不能开放显示::0
打开终端并运行此命令xhost +.每次重新启动计算机时都需要运行此命令。如果一切工作正常,可以将此添加到启动命令中
还要确保在/etc/environment文件中有一行
出口显示=:0.0
然后,运行测试以查看问题是否得到解决。