Chrome Dev Tools console - select frame programmatically

2.3k Views Asked by At

Using the Chrome Dev Tools console, I'm trying to select an element inside an iframe on the page. Is there a way to do this programmatically without having to select the frame in the frames dropdown in order to set the console context to that frame first? Assuming the target iframe is frames[1], and the element inside that iframe has an id of "some-elem", the following does not seem to work:

frames[1].document.getElementById('some-elem');
1

There are 1 best solutions below

2
On BEST ANSWER

I think you want contentDocument instead of document (see this related question).

Note that this will only work if iframe and main document are in the same domain. Otherwise, you are attempting cross-site scripting and it will be blocked by the browser.

iframe access blocked by the browser