我目前正在使用Selenium Webdriver对页面进行一些验证。Webdriver由PhantomJS驱动。我知道在PhantomJS中,可以通过以下示例监听网络:(来自https://github.com/ariya/phantomjs/wiki/Network-Monitoring)。
var page = require('webpage').create();
page.onResourceRequested = function (request) {
console.log('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function (response) {
console.log('Receive ' + JSON.stringify(response, undefined, 4));
};
page.open(url);
我该如何在Webdriver中实现这个功能?我能否将函数绑定到DesiredCapabilities上?