res.json
返回空白。 Selenium日志显示已检索到源代码。知道如何正确接收更新的页面源吗?
如果我使用get current url等其他函数,它会返回相同的内容。
代码:
var driver = new webdriver.Builder().usingServer('http://localhost:4444/wd/hub').withCapabilities(webdriver.Capabilities.firefox()).build();
driver.get('http://www.google.com');
var source = driver.getPageSource();
console.log(source);
res.json({ message: source });
console.log
输出:
[{ then: [Function: then],
cancel: [Function: cancel],
isPending: [Function: isPending] }
Selenium log:
16:17:30.273 INFO - Executing: [new session: Capabilities [{browserName=firefox}]])
16:17:30.286 INFO - Creating a new session for Capabilities [{browserName=firefox}]
16:17:39.751 INFO - Done: [new session: Capabilities [{browserName=firefox}]]
16:17:39.862 INFO - Executing: [get: http://www.google.com])
16:17:43.828 INFO - Done: [get: http://www.google.com]
16:17:43.863 INFO - Executing: [get page source])
16:17:44.036 INFO - Done: [get page source]
16:17:44.081 INFO - Executing: [delete session: d816aa4f-f5ad-4a59-aec0-4475cab4dff1])
16:17:44.206 INFO - Done: [delete session: d816aa4f-f5ad-4a59-aec0-4475cab4dff1]
答案 0 :(得分:1)
source
是获得来源的promise,而不是来源本身。我希望你必须这样做:
source.then(function (src) {
res.json({ message: src });
});
线索是,当您将source
输出到控制台时,您会得到一个具有then
,cancel
和isPending
方法的对象。 promise框架经常使用then
方法来传递将在解析promise时调用的回调。