How to switch the focus of the elements between frames
An iFrame is an HTML document embedded into another HTML document on the website. We use selectFrame command to select and deselect the frame on the application. The iframe element is selected by providing its id, name or title attribute in the target field.
This example demonstrates how to perform actions on the elements inside the frame by selecting the frame and switching back to the parent frame or parent page within the context of an automated test in execution
Solution:
# | Command | Target | Value |
---|---|---|---|
Launch Application | |||
1 | open | / | |
Select the frame | |||
2 | selectFrame |
//iframe[@name="vfFrameId"] | |
Enter an email address in the input field | |||
3 | type | //input[@id="Email"] |
testautomation@yahoo.com |
Verify the email address we entered in the input field | |||
4 | assertText | //input[@id="Email"] | testautomation@yahoo.com |
Switch back to the parent frame | |||
5 | selectFrame | relative=up | |
Verify the save button | |||
6 | assertElementPresent |
//input[@name="save"] | |
Click on the Save button | |||
7 | click |
//input[@name="save"] | |
Tips, Tricks, Gotchas & Best Practices:
- If we know the total number of frames on the web page, then we can select frame using “ index”. Index values help to easily switch between frames. An index will start from Zero i.e. if a web page has only one frame then its index will be Zero
- The parent frame or page can be selected with relative = top or index = -1
Solution:
Consider a business domain site, in which you need to fill out your details in a form to create an account. If the form is in an iframe you cannot enter the details directly. In such a case, you require to select that particular frame and continue the actions. Once the required actions have been performed inside a frame, it is always advisable to come out of the selected frame.