Firefox的Webdriver日志

ale*_*cxe 12 firefox logging selenium google-chrome selenium-webdriver

两者ChromePhantomJSselenium驱动程序都可以记录浏览器端的所有内容.通过在初始化驱动程序时指定服务日志路径,您可以控制将日志写入的位置.例如对于chrome(在Python中):

from selenium import webdriver

driver = webdriver.Chrome(service_log_path="/tmp/log")
driver.get("http://www.google.com")
driver.close()
Run Code Online (Sandbox Code Playgroud)

执行代码后,/tmp/log文件将包含有助于调试的服务日志:

[0.985][INFO]: Launching chrome: ...
[2.620][INFO]: RESPONSE InitSession {
   "acceptSslCerts": true,
   "applicationCacheEnabled": false,
   "browserConnectionEnabled": false,
   "browserName": "chrome",
   "chrome": {
      "userDataDir": "/var/folders/yy/ppdg927x4zv8b0rbzg1f_jzh0000gn/T/.org.chromium.Chromium.ibsof9"
   },
   "cssSelectorsEnabled": true,
   "databaseEnabled": false,
   "handlesAlerts": true,
   "javascriptEnabled": true,
   "locationContextEnabled": true,
   "nativeEvents": true,
   "platform": "Mac OS X",
   "rotatable": false,
   "takesHeapSnapshot": true,
   "takesScreenshot": true,
   "version": "37.0.2062.120",
   "webStorageEnabled": true
}
[2.677][INFO]: Waiting for pending navigations...
[2.696][INFO]: Done waiting for pending navigations
[3.290][INFO]: Waiting for pending navigations...
[4.338][INFO]: Done waiting for pending navigations
[4.338][INFO]: RESPONSE Navigate
[4.339][INFO]: COMMAND CloseWindow {

}
[4.451][INFO]: RESPONSE CloseWindow
Run Code Online (Sandbox Code Playgroud)

有没有办法获得相同的信息,但使用Firefox网络驱动程序?

从我在源代码中看到的,ChromePhantomJS火起来的新服务,通过subprocess和传递--log-path参数给它.这些服务负责日志记录.至于Firefox驱动程序,它的实现是完全不同的,并且基于FirefoxBinary类.

提供的示例和链接与Python相关,但问题非常通用且与语言无关.非常感谢任何指针.

小智 11

您必须在firefox配置文件中设置日志记录选项,如开发人员提示链接 - https://code.google.com/p/selenium/wiki/DeveloperTips - 您应该使用的控制台日志:

FirefoxProfile p = new FirefoxProfile();
p.setPreference("webdriver.log.file", "/tmp/firefox_console");
WebDriver driver = new FirefoxDriver(p);
Run Code Online (Sandbox Code Playgroud)

对于浏览器日志,您应该使用

webdriver.firefox.logfile 
Run Code Online (Sandbox Code Playgroud)

(https://code.google.com/p/selenium/wiki/FirefoxDriver)

希望这可以帮助.