-2

LIKE UI answer in Chrome Dev Tools export Elements HTML is there any way/mechanism I can do it programmatically?

2 Answers2

1

If I'm understanding you correctly, you could use the Element.outerHTML property and the Clipboard.writeText() API.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • thanks mate for response... queried as its not that easy... am trying to get data from heirarchy like full xpath = /html/body/div[5]/section/div[8]/div[1]/iframe/html/body/iframe/html/body/div[2]/iframe/html/body/div[1]/div[1]/div/div[3]/table/tbody/tr[1]/td[2]/div/div[3] and really not able to get it as a reasult of multiple random iframes in between so easiest for me is to inspect element > go back few keystrocks to find parent > right click > copy >copy element and paste as txt to work... this manual task in automation slowing us down hence trying to find a easier way to automate... – aatolive8 May 12 '20 at 05:50
0

If you want to do it programmatically, then you must have to use jquery, it is the most easiest way!

First you have to include this script tag on the top of your Javascript file

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

Now because even a simple website contain plenty of HTML tags.

If you want to extract specific tag, you have to extract using the ID or CLASS of that tag

For example if i want to extract this tag from a website https://example.com

<h1 id='Header'>Example</h1>

I could simply take its Class name for fetching which is Header

Then using Jquery you can do like this

$.get('https://example.com/').then(function (html) {
// Success response
var $mainbar = $(html).find('#Header');
document.write($mainbar.html());
}, function () {
// Error response
document.write('Access denied');
});
Fareed Khan
  • 2,613
  • 1
  • 11
  • 19