I'm trying to grab HTML from a web page using JavaScript and Selenium behind Nodejs. The Webdriver is using Promises and no matter what I try, all I seem to be able to access is the promise. I started down this path thinking that
driver.page_source
would work, but that was a non-starter both before the promise and the in the callback.
Here's my code:
var webdriver = require("selenium-webdriver");
var urlRoot = "http://www.google.com/finance";
var createWebDriver = function() {
return new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
};
exports.financials = function(symbol, callback) {
var driver = createWebDriver();
driver.get(urlRoot + "?q=" + symbol);
driver.findElement(webdriver.By.linkText("Financials")).click();
console.log("content? = " + driver.findElement(webdriver.By.tagName("body")).getAttribute("innerHTML"));
console.log("table? = " + driver.findElement(webdriver.By.id("fs-table")).getAttribute("outerHTML"));
var contentPromise = driver.getPageSource();
contentPromise.then(function() {
console.log("contentPromise = " + contentPromise);
console.log("content? = " + driver.findElement(webdriver.By.id("fs-table")).getAttribute("outerHTML"));
driver.quit();
return callback(null, contentPromise);
});
};
The output is:
fetchFinancials
content? = Promise::90 {[[PromiseStatus]]: "pending"}
table? = Promise::119 {[[PromiseStatus]]: "pending"}
contentPromise = Promise::130 {[[PromiseStatus]]: "fulfilled"}
content? = Promise::360 {[[PromiseStatus]]: "pending"}
Does anyone know how to extract the HTML from the promise and/or driver?
Thanks in advance.