2016-11-19 40 views
0

當我執行下面的代碼錯誤使用webdriver.firefox時()

from selenium import webdriver 
browser = webdriver.Firefox() 

我收到以下錯誤

Traceback (most recent call last): 
    File "<stdin>", line 2, in <module> 
    File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 103, in __init__ 
    self.binary, timeout) 
    File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__ 
    self.binary.launch_browser(self.profile, timeout=timeout) 
    File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser 
    self._wait_until_connectable(timeout=timeout) 
    File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable 
    raise WebDriverException("The browser appears to have exited " 
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. 

什麼我做錯了。

+0

你在Python 3.4.2 – thebadguy

+0

硒版本2.53.2版Firefox 47.0 ubuntu上沒有工作:( –

回答

0

看起來你需要安裝Xvfb然後pyvirtualdisplay。 相反,您可以使用Xephyr或Xvnc。

from pyvirtualdisplay import Display 
from selenium import webdriver 

display = Display(visible=0, size=(1024, 768)) 
display.start() 

browser = webdriver.Firefox() 
+0

使用該硒和Firefox的版本 –

+0

你安裝geckodriver? –