Switch Frame
Last updated
Last updated
The Switch Frame building block is here to help you interact with web pages that use iframes. But first, let's understand what an iframe is and why you might need to switch to one.
An iframe (short for inline frame) is a window within a web page that essentially embeds a different page within the main page. Many websites use iframes to load parts of their content separately, like forms, ads, or other embedded content. The challenge with iframes is that they act as a separate browsing context, meaning you can’t interact with the elements inside an iframe directly unless you "switch" into it.
In the example below, you can see a different website embedded into a web page.
Identify the selector of the iframe. (More about selectors: Using Selectors.)
Select "iframe" in the dropdown and enter your selector.
Once you've specified the iframe, TaskBot will enter that context. From now on, all following building blocks will operate within this iframe until you tell TaskBot to switch back.
Tip! It's recommended to increase selector timeout in the building blocks that rely on selectors (such as Save Web Element, Hover Web Element, etc.) whenever those actions take place within an iframe. You can find the timeout input field in Selector Options directly in those building blocks.
To go back to working on the main page, add another Switch Frame block and select "Main frame" in the dropdown. This action makes TaskBot exit the iframe and resume actions on the main page.
Some web pages contain iframes inside other iframes. If you need to interact with elements within these layers, you can add several Switch Frame building blocks in sequence to navigate to the nested structure. TaskBot will follow each iframe level you define, so you can reach even deeply embedded content.
If TaskBot cannot find the iframe, it will issue an error and stop.
The frame setup will be cleared, as if you had used the Select Main Frame action right before the new tab becomes active. (This handling is available in the upcoming agent 1.1.56.)
Usual ways to obtain selectors continue to work within an iframe. You do not need any special way to find a selector within an iframe or for the iframe itself. For example, if you use a selector picker extension to get selectors, just keep using it.
The reasons why the element cannot be identified can vary:
You have not identified the right iframe selector, so your TaskBot is in the wrong iframe.
Your iframe selector is correct but it is inside another iframe. (See "Nested iframes" example in the section above.)
You have not identified the right click web element selector.
Add a longer selector timeout when performing actions on elements within iframes. (You can find timeout in Selector Options inside those building blocks.)