Hey everyone, I’m stuck on a multi-page form application in Katalon Studio and could really use some help.
On the first page, there was a rich text editor field that I found out was inside an iframe. I looked up a tutorial, added the WebUI.switchToFrame() keyword, and it worked! I was able to type into the field and click the “Next” button to get to page 2.
But now that I’m on the second page, Katalon is failing completely. It tells me it Unable to find element for fields that I can clearly see right there on the screen. I remember reading somewhere that you have to “switch back” or “reset” the focus after using an iframe, but I completely forgot how to do it or what the keyword is called.
What I’ve tried so far:
-
I tried adding a WebUI.delay(5) thinking the page just needed time to load, but it still fails at the exact same spot.
-
I tried capturing the elements on page 2 again, thinking maybe the IDs changed, but Katalon still refuses to interact with them.
I think my test execution is still “trapped” inside that page 1 iframe context, and I don’t know how to break out of it to continue my form. Any help would be appreciated!
After you “switchToFrame” and finish on the <iframe>, like your click or set text, then you have to come back to the main page using “[WebUI] Switch To Default Content | Katalon Docs”.
You should do the same if you “switchToTitle” or “switchToWindowIndex” also.
hi @rhowell
you need to call WebUI.switchToDefaultContent() after you finish interacting with the iframe on page 1
that moves the driver context back to the main page so it can find elements outside the iframe again
WebUI.switchToFrame(findTestObject('Page1/iframe_RichText'), 5)
WebUI.setText(findTestObject('Page1/RichTextField'), 'some text')
WebUI.switchToDefaultContent() // back to main document
WebUI.click(findTestObject('Page1/btn_Next'))
put that switchToDefaultContent call right after your last interaction inside the iframe, before you click Next or do anything on page 2
switch back to the default content as already suggested , it may solve your issue
You need to switch back to the main document after finishing with the iframe. In Katalon, that’s WebUI.switchToDefaultContent().
What to do
Put this right after your last action inside the iframe, before you move on to page 2:
WebUI.switchToFrame(findTestObject('Page1/iframe_RichText'), 5)
WebUI.setText(findTestObject('Page1/RichTextField'), 'some text')
WebUI.switchToDefaultContent()
WebUI.click(findTestObject('Page1/btn_Next'))
Why it happens
switchToFrame() keeps the driver focused inside that iframe. If you don’t switch back, Katalon keeps looking for the page 2 elements inside the iframe context, so elements that are visible on the screen still appear “not found.”
Tip
Use switchToDefaultContent() any time you finish with an iframe and want to interact with normal page elements again
When you use WebUI.switchToFrame(), you are instructing the underlying WebDriver to change its scope of operations from the main web page (the Default Content) into the sub-document embedded inside the <iframe>.
Think of it like walking into a closed room inside a house. Once you are in that room, you can only interact with things inside that room. Even if the application visually navigates to “Page 2” or changes the UI, if that iframe container wasn’t explicitly exited, Katalon is still looking for elements inside that original “room”—which no longer exists or doesn’t contain your new form fields.
The Solution: Switch Back to Default Content
To fix this, you must explicitly tell Katalon to leave the iframe and return to the main page hierarchy before you try to interact with any elements on Page 2. Katalon Studio provides a built-in keyword specifically for this: WebUI.switchToDefaultContent().
Implementation Example
Here is how your test script should look to handle entering, working inside, and safely exiting an iframe.
In Web Script View:
Groovy
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.model.FailureHandling as FailureHandling
WebUI.openBrowser('')
WebUI.navigateToUrl('http://your-form-app.com')
// --- PAGE 1: Interacting inside the iframe ---
// 1. Switch focus into the iframe container
WebUI.switchToFrame(findTestObject('Object Repository/Page_Form/iframe_RichTextEditor'), 10)
// 2. Interact with the elements inside the iframe
WebUI.setText(findTestObject('Object Repository/Page_Form/input_InsideFrameTextField'), 'Entering text inside frame...')
// 3. CRITICAL STEP: Break out of the iframe back to the main webpage
WebUI.switchToDefaultContent()
// 4. Click the Next button (which lives on the main page, outside the iframe)
WebUI.click(findTestObject('Object Repository/Page_Form/button_NextPage'))
// --- PAGE 2: Standard execution resumes ---
// Now Katalon can successfully find these elements because it's back in the default context
WebUI.waitForElementVisible(findTestObject('Object Repository/Page_Form2/input_FirstName'), 10)
WebUI.setText(findTestObject('Object Repository/Page_Form2/input_FirstName'), 'Alex')
WebUI.setText(findTestObject('Object Repository/Page_Form2/input_LastName'), 'Smith')
WebUI.closeBrowser()
Architectural Golden Rule:
Always pair your switches. Every time you write WebUI.switchToFrame(), immediately write the corresponding WebUI.switchToDefaultContent() a few lines down before you forget. Keeping these actions bounded ensures your scripts never lose track of where they are in the webpage DOM hierarchy.
Did any of the solution worked?
The iframe explanation makes sense. I’ve run into similar behavior before where the test looks fine visually, but WebDriver is still scoped to the previous frame, so every locator after that starts failing.
One thing that helped me debug it was adding a quick WebUI.switchToDefaultContent() before moving to the next page, then using waitForElementVisible on the first element of the new page instead of clicking too fast after navigation. If that fixes it, then the issue is probably not the locator itself, but the browser context still being in the wrong place.