3
我开始学习如何在Django中创建Web应用程序时成为更好的测试驱动开发人员。我正在尝试使用Selenium来打开浏览器,但是我收到了错误消息。Selenium无法打开Firefox 48.0.1
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/xn/bvyw0fm97j1_flsyggj0xn9r0000gp/T/tmptoxt890d If you specified a log_file in the FirefoxBinary constructor, check it for details.
我读过“安装FF扩展”禁用附加组件兼容性检查“跳过这一切都很好。” selenium.common.exceptions.WebDriverException: Message: Can't load the profile。我做到了这一点,但它仍然无法正常工作。我在Selenium版本2.53.6中使用了Python2.7和Python3.5。
Python的文件
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import unittest
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox(capabilities=caps)
def tearDown(self):
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('http://localhost:8000')
self.assertIn('To-Do', self.browser.title)
if __name__ == '__main__':
unittest.main(warnings='ignore')
堆栈跟踪
Creating test database for alias 'default'...
EException ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x103f652b0>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 151, in __del__
self.stop()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 123, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
======================================================================
ERROR: test_can_start_a_list_and_retrieve_it_later (functional_tests.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/timothybaney/Treehouse/TDD/superlists/functional_tests.py", line 13, in setUp
self.browser = webdriver.Firefox(capabilities=caps)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 82, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 62, in start
stdout=self.log_file, stderr=self.log_file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
NotADirectoryError: [Errno 20] Not a directory
----------------------------------------------------------------------
Ran 1 test in 0.012s
FAILED (errors=1)
Destroying test database for alias 'default'...
真棒,它的工作。谢谢Yacdaniel Hurtado!现在我可以继续学习。 – JBT
我有这个工作,我不知道晚上发生了什么,但现在我得到这个问题。 NotADirectoryError:[Errno 20]不是目录。我是否必须将我的计算机上的Firefox可执行文件的路径传递给Firefox以及功能? – JBT
是的,你可以添加它:'caps [“binary”] =“/ usr/bin/firefox” 但它看起来像其他类型的问题,你改变了你的代码或什么? –