2017-01-18 77 views
0

我有一個Selenium腳本,它正確地在PC和服務器上工作。幾天前它停止了服務器,但我還沒有弄清楚什麼是錯的。我通過PC和本地設置了Firefox(41.0.2)和Selenium(2.53.5)。Selenium在服務器上無法正常工作

運行:

from selenium import webdriver 

browser = webdriver.Firefox() 

隨着當前版本我面對這樣的錯誤:

selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details. 

我要指出,我跑我的代碼以設置DISPLAY:= 1;

我決定硒升級到3.0.2,我面對的:

IOError: [Errno 13] Permission denied: 'geckodriver.log' 

基於誰遇到這個問題其他人的建議,我下載geckidriver並把它在/ usr/local/bin目錄。但是,我仍然無法運行我的代碼。奇怪的部分是代碼運行沒有任何問題,通過電腦!

任何意見或建議?

這是geckodriver.log的輸出:

(firefox:94561): GConf-WARNING **: Client failed to connect to the D-BUS daemon: 
/usr/bin/dbus-launch terminated abnormally without any error message 
1484733755568 geckodriver  INFO Listening on 127.0.0.1:35823 
1484733756567 mozprofile::profile  INFO Using profile path  /tmp/rust_mozprofile.UiIxs53qoUs1 
1484733756568 geckodriver::marionette INFO Starting browser /usr/bin/firefox 
1484733756573 geckodriver::marionette INFO Connecting to Marionette on localhost:44907 

(process:95171): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed 

Xlib中:擴展名 「RANDR」 缺失上顯示 「:1」。

(firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon: 
/usr/bin/dbus-launch terminated abnormally without any error message 

(firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon: 
/usr/bin/dbus-launch terminated abnormally without any error message 

(firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon: 
/usr/bin/dbus-launch terminated abnormally without any error message 

    (firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon: 
/usr/bin/dbus-launch terminated abnormally without any error message 

感謝

+0

這是我的geckodriver.log: – Moohebat

回答

0

問題已經解決了。我正在運行硒無頭,甚至我設置DISPLAY =:1它不能正常工作。後來我把它改爲

export DISPLAY=:99 

它又開始工作了。我懷疑我有一些未掛起的過程,他們阻止了我的DISPLAY。通過檢查我的過程,我有許多待定的Firefox進程。殺死所有人後。

export DISPLAY=:1 
firefox 

和:對硒2.53.5和Firefox 45

所以沒有任何問題我的代碼運行,我建議,如果你的代碼是之前正常工作,突然你的硒停止工作,通過檢查你的DISPLAY如果此錯誤上升:

Maximum number of clients reachedError: cannot open display: :1 selenium 

,並在同一時間它適用於:

export DISPLAY=:99 
firefox 

您應該檢查正在使用DISPLAY 1的暫停過程。

我希望它能提供幫助。

1

您需要首先設置的屬性這樣

System.setProperty("webdriver.firefox.marionette", getRootDir()+ "/src/main/java/configuration/geckodriver"); 

其中getRootDir()是絕對路徑

然後創建驅動程序

driver = new FirefoxDriver(); 
相關問題