Protractor: getInnerHtml() is not a function but getText() works

Created on 31 Jan 2017  路  5Comments  路  Source: angular/protractor

Bug report

  • Node Version: 7.4.0
  • Protractor Version: 5.0.0
  • Angular Version: 2.4.4
  • Browser(s): chrome
  • Operating System and Version OSX Sierra 10.12.2
  • Your protractor configuration file
  • A relevant example test
let error = 'An error occurred loading that page. Please try again.';
let securityError = 'Request rejected. You do not have permission for the resource requested.';

let pageContainer = this.master.pageContainer();

pageContainer.isPresent().then((present) => {
    console.log('expectNoErrorPage => present', present);
    console.log('expectNoErrorPage', pageContainer);

    if (!present) {
        return;
    }

    // Works
    pageContainer.getText().then((text) => console.log('expectNoErrorPage text', text));

    // Boom
    pageContainer.getInnerHtml().then((html) => console.log('expectNoErrorPage html', html));

    // Original code that blows up below..
    // expect(pageContainer.getInnerHtml()).not.toContain(error);
    // expect(pageContainer.getInnerHtml()).not.toContain(securityError);
});
  • Output from running the test
expectNoErrorPage => present true
expectNoErrorPage ElementFinder {
... lots of stuff
}
....
Failed: pageContainer.getInnerHtml is not a function
  • Steps to reproduce the bug

use .getInnerHtml() or .getOuterHtml()

  • The URL you are running your tests against (if relevant)

Most helpful comment

So the changelog says, we have to replace all:
let i = element(locator).getInnerHtml();
by:
let i = browser.executeScript("return arguments[0].innerHTML;", element(locator));
I really really prefer the first form which was natural and fully comprehensive for human being. Is it possible to revert that removal ?

All 5 comments

Please read the changelog, this was covered as a breaking change as well as a work around.

@cnishina shame you can't do something to the typings and TS to highlight issues like that

What was the an actual reason those methods were removed from the Selenium WebDriver without replacements? Also curious, how can we update the public Any Angular 4 / protractor documentation to reflect the change. The ElementFinder API still states that this should be a working function.

So the changelog says, we have to replace all:
let i = element(locator).getInnerHtml();
by:
let i = browser.executeScript("return arguments[0].innerHTML;", element(locator));
I really really prefer the first form which was natural and fully comprehensive for human being. Is it possible to revert that removal ?

Coming back from the future it's seems that it's now possible to do:

let i = browser.element(locator).getAttribute('innerHTML')

(See https://stackoverflow.com/a/27571812/3482730)

Was this page helpful?
0 / 5 - 0 ratings