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.
We can get the value of a HTML input with Selenium webdriver. This is achieved with the help of the getAttribute() method. To retrieve the value of the field with tagname input, we have to pass the value as parameter to the getAttribute() method. Let us consider an html code for a html input.
get_attribute(innerHTML) gets the innerHTML of the element. This method will first try to return the value of a property with the given name. If a property with that name doesn't exist, it returns the value of the attribute with the same name. If there's no attribute with that name, None is returned.
Method #1 – Read the innerHTML attribute to get the source of the content of the element. innerHTML is a property of a DOM element whose value is the HTML that exists in between the opening tag and ending tag. This property can use to retrieve or dynamically insert content in a web page.
.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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With