我嘗試在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