Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 841
jemiloii Avatar asked Sep 01 '16 15:09

jemiloii


People also ask

How to get HTML tag value in 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.

Which method will return the value of the innerHTML text in selenium?

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.

Which of the following selenium method is used to get content which is inside any HTML tags?

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.


1 Answers

.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).

like image 104
alecxe Avatar answered Sep 21 '22 06:09

alecxe