// get iframe DOM elementconst el = document.getElementsByTagName('iframe')[0].contentDocument// query element within iframeconst abbrEl = getElementsByTagName('abbr')[0]
If the iframe is from a different domain/orign, you will bump into Uncaught DOMException: Blocked a frame with origin "http://..." from accessing a cross-origin frame
.
If you own both the main page and iframe page, you could use the window.postMessage hack.
Alternatively, you can disable same-origin policy in your browser.
- Chrome:
google-chrome --disable-web-security --disable-site-isolation-trials
- Selenium Chrome Web Driver
NOTE: Remember not to use the browser for normal browsing due to security risk