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:
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:
If the iframe’s URL is from the same domain as the host site then the iframe’s content is accessible using this:
The same method that we used to find the iframe can be used inside of it, for example:
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].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()