ruby - 通过 Ruby WebDriver 获取 chrome 控制台日志

标签 ruby webdriver selenium-webdriver selenium-chromedriver

这个问题之前已经用 Java 回答过(Get chrome's console log)

但是,我正在使用 Ruby 绑定(bind),想知道它是否提供了类似的功能?

我查看了 Ruby 源代码,但看不到对 LoggingPreferences 的任何提及或引用。

顺便说一句,我正在使用 RemoteWebDriver 并传入所需的功能对象。大概我想在该对象中设置日志记录首选项,但我很难看到在哪里。

最佳答案

抱歉回复晚了。

我最初是通过在 Webdriver 中添加以下内容来实现的;

module Selenium
  module WebDriver
    class Options

      #
      # Returns the available logs for this webDriver instance
      #
      def available_log_types
        @bridge.getAvailableLogTypes
      end

      #
      # Returns the requested log
      #
      # @param type [String] The required log type
      #
      # @return [Array] An array of log entries
      #
      def get_log(type)
          @bridge.getLog(type)
      end

    end
  end
end

当“需要”时,这导致支持以下内容;

driver.manage.get_log(:browser)

但是,selenium ruby​​ gem 的 2.38 版公开了日志记录 API(尽管是实验性的)。

http://selenium.googlecode.com/git/rb/CHANGES

https://code.google.com/p/selenium/wiki/Logging

因此,从 2.38 开始,以下内容无需上述扩展即可工作;

driver.manage.logs.get :browser

关于ruby - 通过 Ruby WebDriver 获取 chrome 控制台日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18846384/

相关文章:

java - 没有这样的元素 : Unable to locate element: exception coming in selenium

ruby-on-rails - Heroku:rake 中止错误

ruby - Ruby 中的序列

selenium - 无法使用 selenium webdriver 3.0.0-beta3 捕获完整网页屏幕截图

c# - 如何从javascript返回一个数组? (执行脚本)

java - Selenium 没有使用 Chromedriver 通过 xpath 找到元素

python - 如何正确停止 phantomjs 执行

ruby - 在 Ruby 中将散列展平为字符串

ruby-on-rails - 未定义方法send_data

python - 如何在 Firefox geckodriver 中使用代理?