2016-11-12 57 views
-1

我剛剛開始使用win10學習Django和git。無法測試我的第一個Django代碼

我創建了一個叫做functional_tests.py用下面的代碼Python文件:

from selenium import webdriver 
browser = webdriver.Firefox() 
browser.get('http://localhost:8000') 
assert 'Django' in browser.title 

當然,我得到了一個Firefox窗口並顯示錯誤消息彈出當我嘗試單獨運行此文件pyhton

然後,在混帳bash中我做的:

$django-admin.py startproject superlists 
$cd superlists 
$python manage.py runserver 

在另一個命令外殼,我做的: $python functional_tests.py

我應該有一個Firefox窗口彈出消息祝賀我。

相反,沒有Firefox窗口彈出,我有這樣的錯誤:

Traceback (most recent call last): 
    File "functional_tests.py", line 3, in <module> 
    browser = webdriver.Firefox() 
    File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py",  line 134, in __init__ 
    self.service = Service(executable_path, log_path=log_path) 
    File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\service.py", li ne 45, in __init__ 
    log_file = open(log_path, "a+") 
PermissionError: [Errno 13] Permission denied: 'geckodriver.log' 
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firef ox.service.Service object at 0x03347D10>> 
Traceback (most recent call last): 
    File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", lin e 163, in __del__ 
    self.stop() 
    File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", lin e 129, in stop 
    if self.log_file != PIPE: 
AttributeError: 'Service' object has no attribute 'log_file' 

我已經添加了Firefox和geckodriver在PATH

回答

0

從錯誤中,看起來像硒試圖創建失敗日誌文件的壁虎:

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

這可能是試圖爲geckodriver家住在哪裏創建在同一目錄下的日誌文件。相反,請在驅動程序設置中明確設置日誌路徑:

browser = webdriver.Firefox(log_path=<some writable file here>)