【问题标题】:Selenium WebDriverException: Reached error pageSelenium WebDriverException:到达错误页面
【发布时间】:2017-10-04 09:51:02
【问题描述】:

我正在关注 Django TDD 教程:
http://www.marinamele.com/taskbuster-django-tutorial/taskbuster-working-environment-and-start-django-project
在我启动开发服务器 'python manage.py runserver' 之前和之后运行 'all_users.py' 时出现以下错误:

Traceback(最近一次调用最后一次): 文件“functional_tests/all_users.py”,第 15 行,在 test_it_worked self.browser.get('http://localhost:8000') 文件“/Users/samgao/.virtualenvs/tb_test/lib/python3.6/site->packages/selenium/webdriver/remote/webdriver.py”,第 264 行,在 get self.execute(Command.GET, {'url': url}) 文件“/Users/samgao/.virtualenvs/tb_test/lib/python3.6/site->packages/selenium/webdriver/remote/webdriver.py”,第 252 行,在执行 self.error_handler.check_response(响应) 文件“/Users/samgao/.virtualenvs/tb_test/lib/python3.6/site->packages/selenium/webdriver/remote/errorhandler.py”,第 194 行,在 check_response 引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.WebDriverException:消息:到达错误页面:>about:neterror?e=connectionFailure&u=http%3A//localhost%3A8000/&c=UTF->8&f=regular&d=Firefox%20can%E2%80%99t %20建立%20a%20连接%20to%20the%20s>erver%20at%20localhost%3A8000。

基本上无法建立到本地主机的连接。
设置和配置与上一个链接中的教程相同。

我已经为这个问题苦苦挣扎了两天,如果您能提供任何帮助,我将非常感谢您。

【问题讨论】:

    标签: firefox selenium-webdriver python-3.6 django-1.8


    【解决方案1】:

    因为这是“服从测试山羊”的快照(大约 Django 1.8 的时间)——也许那里的说明不再相关。我建议going straight to the goat's mouth 重新开始!

    该问题可能与 virtualenvwrapper(不再需要)有关,也可能与您尝试访问的端口/地址有关。取决于您的 Selenium 版本和 Firefox there may be issues related to that as well

    【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,最终解决方法是:重新安装一遍geckodriver

    1. 解压 geckodriver.zip
    2. 将文件移动到/usr/bin目录sudo mv geckodriver /usr/bin
    3. 转到 /usr/bin 目录 cd /usr/bin,然后您需要运行 sudo chmod a+x geckodriver 之类的东西来将其标记为可执行。

    【讨论】:

      【解决方案3】:

      这可能不是您的情况,但是在运行测试(同一本书,呵呵)时我得到了相同的错误消息,而没有任何实际监听目标端口(在我的情况下为 8000)。通过手动打开浏览器并转到 localhost:8000,确保有东西在监听请求。就我而言 - 愚蠢的我 - 我根本没有启动服务器 =)

      【讨论】:

        【解决方案4】:

        我遇到了同样的错误,为我解决的问题是从 localhost 更改为 127.0.0.1

        • self.browser.get('http://localhost:8000')

        • 更好self.browser.get('http://127.0.0.1:8000')

        【讨论】:

        • 这对我有用。我激活了 virtualenv,django 服务器正在运行,但仍然出现错误。 Firefox 启动,尝试访问 http://localhost:8000,但失败了,因此 selenium 引发了异常。但是当我手动刷新浏览器时,页面会加载。如果我按照您的建议将代码更改为self.browser.get('http://127.0.0.1:8000'),则页面第一次加载,不会引发异常并且测试通过。诡异的。我想知道 Chrome 而不是 Firefox 是否也会发生同样的情况?
        【解决方案5】:

        我也遵循了相同的教程并遇到了相同的错误。我注意到我没有运行 django 服务器。以下是有帮助的。

        python manage.py runserver
        python functional_test.py
        

        【讨论】:

          【解决方案6】:

          视情况而定。

          根据我的情况,我更改了目标网址后,可以让浏览器正常加载网址,也就是说原来的网址不可用了。

          另一种检查方式:

          import requests
          html = request.get(url)
          

          打印 HTML,如果得到 503,则表示该网站是可访问的。

          【讨论】:

            猜你喜欢
            • 2017-07-10
            • 1970-01-01
            • 1970-01-01
            • 2013-05-11
            • 1970-01-01
            • 2018-06-18
            • 1970-01-01
            • 2018-10-31
            • 1970-01-01
            相关资源
            最近更新 更多