How to Work with Frames
The Problem
In this tip, you'll learn how to work with frames and write tests against them.
On occasion, we may encounter relics of the front-end world, such as frames. When writing tests against them, it's easy to make a mistake if we're not paying attention.
A Solution
Rather than getting frustrated when authoring your tests, you can work with the elements in a frame switching to that frame first. Then the rest of your test should be more straightforward.
Let's explore further with some examples.
Examples
Expected Behavior
Example 1
- Open the browser
- Visit the page
- Switch to the nested frame
- Grab the text from the frame and assert that Selenium is in the correct place
- Close the browser
Example 2
- Open the browser
- Visit the page
- Switch to the frame that contains the TinyMCE editor
- Grab and clear the text in the editor
- Input and grab new text in the editor
- Assert that the original and new text entries don't match
- Switch to the top level of the page
- Grab the text from the top of the page and assert that it's not empty
- Close the browser
Outro
Now you're ready to handily defeat frames when they cross your path.
Happy Testing!
Special Thanks
Contributed the Python code for this tip.
Python code review
Python code review
Contributed the initial C# code for this tip.
Contributed the initial Java code for this tip.
Contributed the Serenity/JS code for this tip.
Contributed the Selenide code for this tip.
Authors
Original creator of Elemental Selenium
Current maintainer of Elemental Selenium