getHTML
Get source code of specified DOM element by selector.
Usage
$(selector).getHTML(includeSelectorTag)
Parameters
Name | Type | Details |
---|---|---|
includeSelectorTag optional | Boolean | if true it includes the selector element tag (default: true) |
Examples
- Asynchronous Mode
- Synchronous Mode
index.html
<div id="test">
<span>Lorem ipsum dolor amet</span>
</div>
getHTML.js
it('should get html for certain elements', async () => {
var outerHTML = await $('#test').getHTML();
console.log(outerHTML);
// outputs:
// "<div id="test"><span>Lorem ipsum dolor amet</span></div>"
var innerHTML = await $('#test').getHTML(false);
console.log(innerHTML);
// outputs:
// "<span>Lorem ipsum dolor amet</span>"
});
index.html
<div id="test">
<span>Lorem ipsum dolor amet</span>
</div>
getHTML.js
it('should get html for certain elements', () => {
var outerHTML = $('#test').getHTML();
console.log(outerHTML);
// outputs:
// "<div id="test"><span>Lorem ipsum dolor amet</span></div>"
var innerHTML = $('#test').getHTML(false);
console.log(innerHTML);
// outputs:
// "<span>Lorem ipsum dolor amet</span>"
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.