A very common type of control used in website is the HTML iframe. And this control needs to be handled in a specific manner when testing. This article shows you how to handle iframes properly in akaAT Studio.
What is iframe?
An iframe (Inline Frame) is an HTML document embedded in another HTML document. The iframe HTML element is often used to insert the content from another source, such as an advertisement, into a Web page.
How to identify the iframe?
We can identify the iframes by below two ways by inspecting the element:
Why is it important to know how to test iframes?
Verifying text and objects within iframes can be a challenge. For example, even though you can see a text displayed in an iframe, automation tools may not be able to detect the text. You have to tell your script how to traverse through a website's iframes structure and select the correct iframe where the text and its object are present.
Example #1: Switch to Frame
The sample code below shows how to switch to the parent frame before using the drag and drop action on the elements within the iframe.
Example #2: Switch to Default Content
Whenever we switch to frames to handle certain features, we must switch back to the parent node to access other features of the application. If we do not switch back to the parent node, then your code looks for next locators within that same frame itself.
Switch used to switch back to the main window or parent window frame.
Noted that NoSuchFrameException or InvalidSwitchToTargetException exceptions are thrown when the target frame to be switched to doesn't exist.