我尝试在CentOS7运行无头硒:硒无头不使用Perl在CentOS 7上运行,“无显示指定的”
# cat /etc/os-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.2 (Maipo)"
我安装的Xvfb并运行它作为
# /usr/bin/Xvfb :99
我安装了Firefox:
# firefox -v
Mozilla Firefox 38.5.0
并运行它以检查它是否可以在所有运行:
# export DISPLAY=:99
# firefox
这是输出:
# firefox
Xlib: extension "RANDR" missing on display ":99".
console.error:
[CustomizableUI]
Custom widget with id loop-button does not return a valid node
console.error:
[CustomizableUI]
Custom widget with id loop-button does not return a valid node
GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications.
火狐似乎命令后运行:
# ps aux | grep firefox
root 29476 7.3 14.9 852356 152256 pts/3 Sl+ 10:30 0:03 /usr/lib64/firefox/firefox
编辑 是的,它的运行。以截图从的Xvfb通过
DISPLAY=:99 import -window root -crop 1264x948+0+0 /tmp/screenshot.jpg
现在有问题的部分。
我安装了perl的硒的远程驱动器
# cpanm Selenium::Remote::Driver
然后我跑了独立硒司机:
# java -jar selenium-server-standalone-2.49.0.jar
现在我运行测试脚本:我得到
#!/usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new(browser_name=>'firefox');
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();
后45秒来自驱动程序的错误:
Could not create new session: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
at (eval 89) line 510.
似乎像驱动程序启动的firefox没有看到DISPLAY环境变量。我尝试从脚本中添加它:
#!/usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;
$ENV{DISPLAY}=":99";
my $driver = Selenium::Remote::Driver->new(browser_name=>'firefox');
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();
它没有帮助,前面的错误仍然存在。 我该怎么办?
EDIT2
我想当前设置与Python。所有作品。
# pip install selenium
而且使用了以下测试脚本:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
f = open('ptn-sel.txt', 'w')
f.write(driver.title)
driver.close()
f.close()
我知道这是Perl驱动程序的问题....有什么建议?
我会检查Selenium :: Firefox。但是,如何在服务器中设置DISPLAY? – rlib
在运行独立服务器之前将其导出到shell中,以便独立服务器将其设置在其环境中。 –
解决了这个问题。 export DISPLAY =:99 && java -jar selenium-server-standalone-2.49.0.jar – rlib