<iframeid="myIFrame"src="thispage.html"width="100%"height="600"frameBorder="2"></iframe>
// Get the iframe
const iFrame = document.getElementById('myIFrame');
// Let's say that you want to access a button with the ID `'myButton'`,
// you can access via the following code:
const buttonInIFrame = iFrame.contentWindow.document.getElementById('myButton');
// If you need to call a function in the iframe, you can call it as follows:
iFrame.contentWindow.yourFunction();
<script>setInterval(function(){document.getElementById("iframeId").classList.add('your-class')},500);</script>
Now you need to write css code with your class name. Thank you
<!-- local file: if test.html is in the same directory --><iframesrc="test.html"width="1000"height="1000"><!-- local file: if test.html is in the parent directory --><iframesrc="../test.html"width="1000"height="1000"><!-- online iframe (youtube as an example) --><iframesrc="https://www.youtube.com/embed/s4BibernJxU"width="1000"height="1000">
<!-- This tag is used for rendering one page in another.
It by default has a border--><iframesrc="https://example.com/">This will show if the url does not load</iframe>
<iframesrc="https://player.vimeo.com/video/756532933?h=883e55af4c"frameborder="0"allow="autoplay; fullscreen"allowfullscreen></iframe>
Run code snippet
- Iframe is html inside another html
- We need to switch selenium focus to iframe
either by using INDEX, NAME-ID, or
as a webelement same way as other webelements.
After switching to Iframe we need to switch back to
the main frame to able to continue in the main frame.
Syntax=
-driver.switchTo().defaultContent();
-driver.switchTo().parentFrame();
<iframesrc="https://player.vimeo.com/video/756532933?h=883e55af4c"frameborder="0"allow="autoplay; fullscreen"allowfullscreen></iframe>
Run code snippet
<iframesrcdoc="<html><body>The content you see here will never be affected by the CSS of its parent container. It supposed to be rendered in black on a white background.</body></html>"></iframe>