2017-10-18 16 views
-1

我嘗試運行在Linux machine.But硒程序我得到異常:webdriver的例外:進程意外關閉狀態:1

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__ 
    keep_alive=True) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__ 
    self.start_session(desired_capabilities, browser_profile) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session 
    response = self.execute(Command.NEW_SESSION, parameters) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute 
    self.error_handler.check_response(response) 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1 

如何解決的例外?感謝您的幫助。

+1

你是什麼意思*修復異常*?分享您的代碼 – Andersson

+0

請仔細閱讀[問],特別是關於[mcve](MCVE)的部分,以及[預計需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-研究工作量是預期的堆棧溢出用戶)這將幫助您調試自己的程序併爲自己解決問題。如果你這樣做並且仍然卡住,你可以回過頭來發布你的MCVE,你試過的,以及執行結果,包括任何錯誤信息,這樣我們可以更好地幫助你。還提供了一個鏈接到頁面和/或相關的HTML。 – JeffC

回答

1

很難確定沒有更多信息,但是當您使用的瀏覽器版本與您使用的底層webdriver不兼容時,通常會發生這種情況。

請確保它們是兼容的,例如通過升級您的webdriver,並且應該解決此問題。

5

當您嘗試在沒有顯示器的盒子(如Ubuntu服務器)上以非無頭模式運行瀏覽器時,可能會出現此錯誤。

您可以檢查,如果這是你的Process unexpectedly closed with status: 1錯誤通過查看geckodriver.log文件通常在工作目錄留給你運行你的腳本後的原因,它應該有這樣一行:

Error: GDK_BACKEND does not match available displays 

如果你看到geckodriver.log該行,那麼你就需要切換你的腳本在無頭的模式下運行的Firefox:

from selenium import webdriver 
from selenium.webdriver import FirefoxOptions 

opts = FirefoxOptions() 
opts.add_argument("--headless") 
browser = webdriver.Firefox(firefox_options=opts) 

browser.get('http://example.com')