普通网友 2017-08-09 13:46
浏览 38

水豚等待ajax加载

Hi I have error in my capybara testing env

 unknown error: jQuery is not defined
        (Session info: chrome=43.0.2357.125)

I think it's related to ajax wait function

 def wait_for_ajax
    Timeout.timeout(Capybara.default_wait_time) do
      element = false
      until element do
        begin
          sleep(0.05)
          count = 0
          begin
            element = page.evaluate_script('jQuery.active') == 0
          rescue Errno::ECONNRESET => e
            count += 1
            restart_phantomjs
            retry unless count > RETRY_COUNT_ERROR_CONNECT
          rescue Capybara::Poltergeist::DeadClient
            count += 1
            restart_phantomjs
            retry unless count > RETRY_COUNT_ERROR_CONNECT
          rescue Capybara::Poltergeist::JavascriptError
          end
        end
      end
    end
  end

Any idea how to solve this? Any help is welcomed. Maybe updating chrome driver is required, not sure whats going on.

  • 写回答

1条回答 默认 最新

  • weixin_33704234 2017-08-09 17:20
    关注

    The wait_for_ajax method you show is specifically written to be used with Poltergeist and requires jQuery to be loaded in the page (the Capybara::Poltergeist error rescuing, restart_phantomjs, etc) so you should not be using it with what appears to be selenium-webdriver using Chrome.

    There's also the fact that wait_for_ajax shouldn't be needed 99.9% of the time with Capybara 2.1+, when used correctly, since it will automatically wait for elements/text to appear so whether it's coming from an ajax request or a page load shouldn't matter. That combined with the fact that more and more libraries are using XMLHttpRequest directly rather that through jQuery means wait_for_ajax is virtually unnecessary. Pretty much the only exception to that is when you have a badly designed UI that provides no feedback to the user about background requests and their effects, in which case I'd suggest fixing your UI.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀