question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: access elements in iframe

See original GitHub issue

Hi 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:

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:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
paulirishcommented, Nov 3, 2018

@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.

1reaction
jsoversoncommented, Nov 3, 2018

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 on Page.getFrameTree() may be worthwhile in order to save people the headache in the future.

Thanks again 🙂

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found