I am new at testing so my apologies in advance if my question sounds a bit primary.
I am using Selenium and Java to write a test.
I know that
webElement.getAttribute("innerHTML");
brings me the innerHTML, for example for the element below:
<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" style="position: absolute; border-radius: 0px 0px 4px 4px;">
<span class="ui-icon ui-icon-closethick">close</span>
</a>
it returns:
<span class="ui-icon ui-icon-closethick">close</span>
but I need something that brings me the inner attribute of WebElement "a", something like below:
href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" style="position: absolute; border-radius: 0px 0px 4px 4px;"
Try
.getAttribute("innerHTML");
function to extract source in string formExample code:
You can read innerHTML attribute to get source of the content of the element or outerHTML for source with the current element.
Example :- Now suppose your Element is as below
Inner element Output
Outer element Output
Live Example :-
http://www.java2s.com/Tutorials/JavascriptDemo/f/find_out_the_difference_between_innerhtml_and_outerhtml_in_javascript_example.htm
Below you will find the syntax which require as per different binding. Change the
innerHTML
toouterHTML
as per required.Python:
Java:
C#:
Ruby:
JS:
If you want whole page HTML use below code :-
or to get them all:
If you want the HTML of the element itself, you can use
It will return the HTML of the element itself plus all the children elements. I'm not sure if that's exactly what you want. I don't think there is a way to just get the HTML of the selected element only.
If we have this:
and we need to get all attributes of "a" which will be this:
We can use this code:
where webElement is "a".
Or more precisely: