4

我需要从动态构建的页面获取数据,我找到的一个解决方案是 Watir。

irb 的下一个代码可以正常工作:

require 'rubygems'
require 'watir-webdriver'
require 'headless'

Headless.ly do
  browser = Watir::Browser.new :firefox
  browser.goto "google.com"
  browser.close
end

如果我尝试从 Rails 应用程序运行它有下一个问题:

宝石文件:

gem 'headless'
gem 'watir-webdriver'

行动:

def test_action
    Headless.ly do
          browser = Watir::Browser.new(:firefox)
          browser.goto "google.com"
          browser.close
     end
end

有下一个输出:

no such file to load -- {
  "frozen": {
    "app.update.auto": false,
    "app.update.enabled": false,
    "browser.download.manager.showWhenStarting": false,
    "browser.EULA.override": true,
    "browser.EULA.3.accepted": true,
    "browser.link.open_external": 2,
    "browser.link.open_newwindow": 2,
    "browser.offline": false,
    "browser.safebrowsing.enabled": false,
    "browser.safebrowsing.malware.enabled": false,
    "browser.search.update": false,
    "browser.sessionstore.resume_from_crash": false,
    "browser.shell.checkDefaultBrowser": false,
    "browser.tabs.warnOnClose": false,
    "browser.tabs.warnOnOpen": false,
    "devtools.errorconsole.enabled": true,
    "dom.disable_open_during_load": false,
    "extensions.autoDisableScopes": 10,
    "extensions.logging.enabled": true,
    "extensions.update.enabled": false,
    "extensions.update.notifyUser": false,
    "network.manage-offline-status": false,
    "network.http.phishy-userpass-length": 255,
    "offline-apps.allow_by_default": true,
    "prompts.tab_modal.enabled": false,
    "security.fileuri.origin_policy": 3,
    "security.fileuri.strict_origin_policy": false,
    "security.warn_entering_secure": false,
    "security.warn_entering_secure.show_once": false,
    "security.warn_entering_weak": false,
    "security.warn_entering_weak.show_once": false,
    "security.warn_leaving_secure": false,
    "security.warn_leaving_secure.show_once": false,
    "security.warn_submit_insecure": false,
    "security.warn_viewing_mixed": false,
    "security.warn_viewing_mixed.show_once": false,
    "signon.rememberSignons": false,
    "toolkit.networkmanager.disable": true,
    "toolkit.telemetry.prompted": 2,
    "toolkit.telemetry.enabled": false,
    "toolkit.telemetry.rejected": true
  },
  "mutable": {
    "browser.dom.window.dump.enabled": true,
    "browser.startup.page": 0,
    "browser.startup.homepage": "about:blank",
    "dom.max_script_run_time": 30,
    "dom.report_all_js_exceptions": true,
    "javascript.options.showInConsole": true,
    "network.http.max-connections-per-server": 10,
    "webdriver_accept_untrusted_certs": true,
    "webdriver_assume_untrusted_issuer": true
  }
}

问题在哪里?

4

3 回答 3

2

My project have the same errors with you

I found this question cauesed by the gem "selenium-webdriver"

and the verion should be '2.20.0'

If you gem's version is higher than this, this error would happen

于 2012-04-24T14:55:41.923 回答
1

just put this code in your initializers directory, works with 'watir-webdriver', '0.5.5'

require 'childprocess'
require 'tmpdir'
require 'fileutils'
require 'date'

require 'multi_json'
require 'selenium/webdriver/common'

module Selenium
  module WebDriver

    if MultiJson.respond_to?(:load)
      # @api private
      def self.json_load(obj)
        MultiJson.decode(obj)
        #MultiJson.load(obj) here was mistake
      end
    else
      # @api private
      def self.json_load(obj)
        MultiJson.decode(obj)
      end
    end

  end
end
于 2012-04-25T13:04:39.053 回答
0

这里讨论的问题

要解决它,您还可以尝试更新 multi_json gem,例如:

bundle update multi_json

对我来说,从版本 1.0.3 更新到 1.3.5 解决了这个问题。

于 2012-05-23T23:20:31.030 回答