这个问题之前已经用 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/