Skip to main content
Nintex Community Menu Bar

Working with iframes and additional JavaScript examples

  • August 31, 2022
  • 0 replies
  • 147 views
  • Translate

MillaZ
Nintex Employee
Forum|alt.badge.img+21
  • Nintex Employee
  • 667 replies
Product: Kryon RPA
Product Version:
Components: Kryon Studio
Article Contributors: Richard Holt
This article is dealing with iframes and their difficulties.
Steps:
Iframes are the bane of a lot of people’s existences. With that said, if you know the rules that they obey, they are a lot more predictable.
The most important thing to realize is that the iframe’s source must be sourced from the same domain as the hosting site. If not, browsers will not allow the iframe’s content to be accessed.

To find out if there is an iframe, you can simply type this into the console:
window.document.getElementsByTagName("iframe").length​
If this shows anything greater than 1, then you have an iframe in your page. You can then test the source of the iframe by running this in the console:

window.document.getElementsByTagName("iframe")[0].src​
If the iframe’s URL is from the same domain as the host site then the iframe’s content is accessible using this:

window.document.getElementsByTagName("iframe")[0].contentDocument.<element inside of the iframe>
The same method that we used to find the iframe can be used inside of it, for example:

window.document.getElementsByTagName("iframe")[0].contentDocument.getElementsByTagName('button')[0].click()​
What this does is create an array of that element by tag name. Also, the “contentDocument” is the way to access the “document” of the iframe’s inner HTML.

Additionally the site here: https://adoring-swirles-818bce.netlify.app/html%202.html, has an iframe inside of an iframe with multiple layers of buttons, links, divs, tables, and more for your testing.

To click the button in the second iframe use something like this:
 
window.document.getElementsByTagName("iframe")[0].contentDocument.getElementsByTagName("iframe")[0].contentDocument.getElementsByTagName('button')[0].click()

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings