1

Struggling a bit to simultaneously understand WebDriverJS and promises... and most of the sample code out there is for Python/Java, not Javascript. All I'm trying to do is to get the full html for a page. So if you look at the same code for WebDriverJS:

var webdriver = require('selenium-webdriver');
...
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
 return driver.getTitle().then(function(title) {
 return title === 'webdriver - Google Search';
 });
}, 1000);

I'm trying to simply return the entire html document instead of just the title. In Python that'd be driver.page_source. I learn much better from examples so I'm a bit flummoxed here.

alecxe
476k127 gold badges1.1k silver badges1.2k bronze badges
asked Sep 19, 2014 at 22:39

1 Answer 1

3

I usually prefer to explore the source code in case the documentation is not clear.

Here's the the main webdriver.js source that contains relevant getPageSource() function:

/**
 * Schedules a command to retrieve the current page's source. The page source
 * returned is a representation of the underlying DOM: do not expect it to be
 * formatted or escaped in the same way as the response sent from the web
 * server.
 * @return {!webdriver.promise.Promise.<string>} A promise that will be
 * resolved with the current page source.
 */
webdriver.WebDriver.prototype.getPageSource = function() {
 return this.schedule(
 new webdriver.Command(webdriver.CommandName.GET_PAGE_SOURCE),
 'WebDriver.getAllWindowHandles()');
};
answered Sep 19, 2014 at 22:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.