JemiloII JemiloII - 1 month ago 25x
Javascript Question

What should we use in place of getInnerHtml() and getOutterHtml() in Selenium?

So selenium deprecated getInnerHtml() and getOutterHtml() and in 3.0 beta they plan on completely removing the functions. I have test that check markup. So what should we be using in their place? Why are they being removed? I use protractor/webdriver.js with selenium.


.getInnerHTML() and .getOuterHTML() methods can be replaced with .getAttribute("innerHTML") and .getAttribute("outerHTML") respectively and, I assume, this is the reason they are deprecated. There is no point in having special methods for these cases while it can be easily retrieved through a "get attribute" call.

Note that getInnerHTML() and getOuterHTML() are not a part of the Protractor public API anymore as well.

FYI, here are the getInnerHTML() and getOuterHTML() method implementations - basically retrieving the innerHTML and outerHTML attribute values (though for "outerHTML" there is a special case handling - when there is no outerHTML attribute available).

By the way, if you want to enforce not having getInnerHTML() and getOuterHTML() in your test codebase, you can use no-get-inner-outer-html ESLint rule from eslint-plugin-protractor plugin (shameless self-promotion).