> For the complete documentation index, see [llms.txt](https://docs.zerowork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zerowork.io/using-zerowork/using-building-blocks/switch-frame.md).

# Switch Frame

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FSWBly8ce16n0WqSR16Al%2Fswitch_frame_block.png?alt=media&amp;token=e7cb85a4-f2d3-4cd9-af98-9e2cb2e18bab" alt="" width="375"><figcaption></figcaption></figure>

The **Switch Frame** block moves your TaskBot into an iframe so the blocks that follow act on the elements inside it.

{% hint style="info" %}
**What's An Iframe?**\
\
An **iframe** is a page embedded inside another page; sites use them for things like forms, checkout widgets, embedded videos, and ads. An iframe is its own separate context, so blocks like [Click Web Element](/using-zerowork/using-building-blocks/click-web-element.md) and [Save Web Element](/using-zerowork/using-building-blocks/save-web-element.md) can't reach inside one until you first switch into it with this block.
{% endhint %}

## How To Use It

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FmnxRVy4xfsgCrtjVwlx5%2Fswitch_frame_settings.png?alt=media&amp;token=04fea0e1-551e-4bf9-8d2a-ca232d4fbedd" alt=""><figcaption></figcaption></figure>

* **Iframe** (default) enters an iframe. Provide a selector for the iframe element (see below).
* **Main page** leaves every iframe and returns to the top-level page.

### Web Element Selector

When the target frame is **Iframe**, enter the CSS or XPath selector that identifies the iframe element on the page; it's the same kind of selector you'd use in other Web Interaction blocks. See [Using Selectors](https://docs.zerowork.io/using-zerowork/using-selectors).

{% hint style="info" %}
You don't need anything special to target an iframe or the elements inside it. If you're using a selector-picker browser extension to help you find an appropriate css selector it works the same as always. If the selector matches more than one iframe, your TaskBot uses the first match.
{% endhint %}

#### Timeout

How long to wait for the iframe element to appear before the block fails, in seconds. The default is **15 seconds**. Raise it if the iframe is slow to load.

#### Block-level Delays

**Min sec** and **Max sec** represent a pause after this block's action completes, before the next block runs. The wait is randomized between the two values, and setting both to the same number makes it fixed. This block defaults to **0**, meaning no pause.

{% hint style="info" %}
See the [Delay](https://docs.zerowork.io/using-zerowork/using-building-blocks/delay) block for how these two fields behave, including decimals, references, and what happens when a field is left empty. See [Delay Times between the Building Blocks](https://docs.zerowork.io/using-zerowork/using-building-blocks/building-block-options/delay-times-between-the-building-blocks) for how block-level delays fit into a TaskBot's run.
{% endhint %}

## Things To Know

* **Switching into an iframe affects blocks after it.** Once you switch into an iframe, every selector-based block after it (Click Web Element, Save Web Element, Hover Web Element, Check Web Element, etc) acts inside that iframe until you switch back or the context is cleared.
* **Return to the main page with a second block.** Add another Switch Frame set to **Main page** to exit all iframes and resume on the top-level page.
* **Nested iframes stack.** For an iframe inside another iframe, add a Switch Frame block for each level in order; each one steps a level deeper. A single **Main page** clears every level at once.
* **Navigating or changing tabs resets it.** [Open Link](https://docs.zerowork.io/using-zerowork/using-building-blocks/open-link), [Go Back or Forward](https://docs.zerowork.io/using-zerowork/using-building-blocks/go-back-or-forward), and [Switch or Close Tab](https://docs.zerowork.io/using-zerowork/using-building-blocks/switch-or-close-tab) clear the frame context on their own, as if you'd switched to Main frame right before. After any of them you're back on the main page and must switch in again.
* **There are two different timeouts to be aware of.** This block's own **Timeout** controls how long it waits for the *iframe element* to appear. The blocks that act *inside* the iframe (Save Web Element, Hover Web Element, etc.) have their own **Timeout** for the elements within it; raise those separately if in-iframe elements are slow to load.

## Block Behavior

**When switching to an iframe that's found** the block enters it and logs that it switched into the iframe. Every selector-based block that follows then resolves its target inside that iframe.

**When the iframe selector can't be found** the block fails with a selector error and stops the run. Wrap it in a [Try-Catch](https://docs.zerowork.io/using-zerowork/using-building-blocks/try-catch) block sequence if you'd rather handle a missing iframe than end the run.

**When switching to Main page** the block clears the frame context and logs that it returned to the main page. Subsequent blocks act on the top-level page again.

**When you navigate or switch tabs** the frame context resets automatically, as if you'd switched to Main page; a Click Web Element or Save Web Element block after an Open Link block then acts on the new page, not a stale iframe.
