Selenium无法打开Firefox 48.0.1

时间:2016-09-05 04:10:00

标签: python selenium firefox

我开始学习如何在Django中创建Web应用程序时成为更好的测试驱动开发人员。我正在尝试使用Selenium打开浏览器,但我收到了错误。

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。我这样做了,但它还没有用。我使用Python2.7和Python3.5与Selenium版本2.53.6。

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'...

1 个答案:

答案 0 :(得分:3)

该错误是因为您使用的是FF 48.对于FF&gt; = 47 FirefoxDriver停止工作。您必须使用新的MarionetteDriver

设置:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True

browser = webdriver.Firefox(capabilities=caps)
browser.get('http://localhost:8000')

assert 'Django' in browser.title