Question: access elements in iframe
See original GitHub issueHi Andrea, I’d like to be able to access elements contained within an iframe. It doesn’t look like this is possible using chrome-remote-interface atm however it is possible using selenium/chromedriver, and of course within chrome it’s possible to change the frame in the devtools.
My questions are:
- did I miss something - is it already possible in chrome-remote-interface?
- have you looked into this before? and if so do you know much about how chromedriver has implemented this feature?
- is it something that you might want to add to chrome-remote-interface?
- do you know of any alternative ways of achieving the objective? I need to find an input element inside an iframe and set the value.
I put together a prototype to demonstrate how you can find elements inside an iframe using selenium/chromedriver (nb python implementation):
The code does the following:
- navigates to https://ilanc.github.io/iframe-chrome-remote-interface/iframe.html
- finds an element ‘#findme’ inside the iframe and logs the innerText (i.e.
document.querySelector('#findme').innerText
)
I’ve started looking into the chromedriver source but have not yet figured out what they’re doing:
- window_commands.cc - look for
ExecuteSwitchToFrame
- session.cc - look for
SwitchToSubFrame
- log of devtools and chromedriver commands executed by iframe prototype
- it doesn’t look like there’s anything in the devtools protocol that allows iframe switching
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Access iframe elements in JavaScript - Stack Overflow
If your iframe is in the same domain as your parent page you can access the elements using window.frames collection.
Read more ><iframe>: The Inline Frame element - HTML - MDN Web Docs
The <iframe> HTML element represents a nested browsing context, embedding another HTML page into the current one.
Read more >Not able to access elements inside iframe
Hi All, I am trying to access elements inside iframe but not able to capture that element instead Testcomplete is taking full screenshot...
Read more >How To Get an Element in an iframe - W3Schools
Click the button to hide the first H1 element in the iframe (another document). Hide H1 Element. Get Element in Iframe. Get the...
Read more >How to get HTML content of an iFrame using JavaScript
3. How to specify the HTML content of the page to show in the iframe element HTML5 ? 4. Resize an iframe ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jsoverson It’s possible that chrome is using Site Isolation aka OOPIF (out of process iframes) for this jsbin iframe. In that case, the iframe is a brand new target.
Hypothetically you can disable OOPIF with
-disable-features=IsolateOrigins,site-per-process
but I haven’t verified this still works. If you can easily disable it, then the child frames should exist as you expect.Thanks @paulirish,
--disable-features=IsolateOrigins,site-per-process
gives me the behavior I was expecting. I was banging my head against that for quite a long time, a warning or notice onPage.getFrameTree()
may be worthwhile in order to save people the headache in the future.Thanks again 🙂