无法测试我的第一个Django代码

2024-04-20 08:56:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚开始使用win10学习Django和git。你知道吗

我创建了一个名为functional的python文件_测试.py代码如下:

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

当然,当我试图单独运行这个pyhton文件时,firefox窗口会弹出一条错误消息

然后,在git bash中我会:

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

在另一个命令shell中,我执行以下操作: $python functional_tests.py

我应该有一个火狐窗口弹出的消息祝贺我。你知道吗

相反,没有弹出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'

我已经在PATH中添加了Firefox和geckodriver


Tags: pathinpybrowserloglibpackagesselenium
1条回答
网友
1楼 · 发布于 2024-04-20 08:56:48

从错误来看,selenium在尝试为gecko创建日志文件时失败:

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

它可能试图在geckodriver所在的目录中创建日志文件。相反,请在驱动程序设置中显式设置日志路径:

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

相关问题 更多 >