问题 Firefox的Webdriver日志


Chrome 和 PhantomJS selenium驱动程序可以记录浏览器端的所有内容。通过在初始化驱动程序时指定服务日志路径,您可以控制将日志写入的位置。例如。 for chrome(在Python中):

from selenium import webdriver

driver = webdriver.Chrome(service_log_path="/tmp/log")
driver.get("http://www.google.com")
driver.close()

执行代码后, /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

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

从我在源代码中看到的两者 Chrome 和 PhantomJS 火起来 新服务 通过 subprocess 并通过 --log-path 论证。这些服务负责日志记录。至于 Firefox 司机,它的实现是完全不同的,并基于 FirefoxBinary 类。

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


3532
2017-09-15 19:23


起源



答案:


您必须在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);

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

webdriver.firefox.logfile 

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

希望这可以帮助。


9
2017-09-24 14:24



日志文件不像Chrome和PhantomJS服务提供的那样详细,但这很有用,并且有助于调试。非常感谢你! - alecxe
你们碰巧知道Chrome的“浏览器日志”吗?即webdriver.firefox.logfile但适用于Chrome。 - Leo Gallucci


答案:


您必须在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);

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

webdriver.firefox.logfile 

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

希望这可以帮助。


9
2017-09-24 14:24



日志文件不像Chrome和PhantomJS服务提供的那样详细,但这很有用,并且有助于调试。非常感谢你! - alecxe
你们碰巧知道Chrome的“浏览器日志”吗?即webdriver.firefox.logfile但适用于Chrome。 - Leo Gallucci


我相信必须通过配置文件启用FireFox的日志记录。哪个需要base64编码。

提到了沿着这些方向的东西 在这个针对RemoteWebDriver引发的bug中

有帮助吗?


1
2017-09-24 13:39