python - 使用 django 进行 Selenium 测试给出 'NoneType' 对象没有属性 'path'

标签 python django selenium

我看不出是什么原因导致此错误发生,因为它没有给我更多信息。测试通过了,但他们将此消息打印到控制台。我将在下面发布我的文件。

测试.py:

class MainAppTests(LiveServerTestCase):
    """Testing the interactions on the main page"""

    def setUp(self):
        """Opening the browser"""
        selenium_logger = logging.getLogger('selenium.webdriver.remote.remote_connection')
        # Only display possible problems
        selenium_logger.setLevel(logging.ERROR)
        self.browser = webdriver.Firefox()
        self.user = make_user()

    def tearDown(self):
        """Closing the browser"""
        self.browser.quit()

    def test_homepage(self):
        """Testing that everything work"""
        self.browser.get(self.live_server_url)
        self.assertIn("Site", self.browser.title)

views.py:

def home(request):
    """View for displaying the home page"""
    if request.user.is_authenticated():
        # Pulling and ordering by the 'full_name' field, shows users what is available
        active_languages = Language.objects.filter(active=True).order_by('full_name')
        context = {'active_languages': active_languages}
        return render(request, 'main/home_loggedin.html', context)
    return render(request, 'main/home_loggedout.html', status=302)

最佳答案

这不是你,而是selenium...:)你的代码是正确的。

这是一个recent issue使用 selenium,在 self.browser.quit() 期间使用 python 客户端发生。

更新 selenium 应该可以解决问题。尽管由于该错误的近期性质(已于 10 月 21 日报告并fixed),但目前修复尚未纳入recent version。 Selenium 。 3.0.1以上版本应该已修复

关于python - 使用 django 进行 Selenium 测试给出 'NoneType' 对象没有属性 'path',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40481906/

相关文章:

python - 用于在 python 中进行单元测试的局部变量,用于验证测试函数的功能

python - 在 Django 表单中动态将 CharField 转换为 ChoiceField?

python - 添加不属于模型的自定义表单字段 (Django)

java - Selenium Web 驱动程序 : findElement(By. 名称 ..... 和 headless 浏览器

java - AspectJ - 捕获所有用 @FindBy 注释的 WebElement 的切入点

python - django 在第一个脚本运行后每天将数据保存到文件中

python - 以括号开头和结尾的正则表达式

python - 使Django不懒加载模块,方便开发

Python/Django : Selecting max value of one-to-many relation and displaying it in HTML/View

javascript - Selenium javascript 自动化 Gmail 登录