[Mobile] Switch To Context
Last updated: October 2026
Description​
Switch the current mobile session to the context with the given name, such as NATIVE_APP or a WebView context of a hybrid app. To get the names of the available contexts, use Mobile.getContexts.
- After you switch to a WebView context (its name starts with
WEBVIEW), WebUI keywords in the same test case run on that WebView through the current mobile session. You do not need a separate browser session. - After you switch to
NATIVE_APPor any other context, WebUI keywords no longer target the WebView, and Mobile keywords work with the native elements again. - If the context is not available yet, for example because the WebView is still loading, the keyword checks the available contexts up to 3 times, 0.5 seconds apart, about 1 second in total. If the WebView in your app takes longer to load, add a wait step before this keyword.
Keyword name: Mobile.switchToContext
Parameters​
| Parameter | Parameter Type | Required | Description |
|---|---|---|---|
| context | String | Yes | The exact name of the context to switch to, for example NATIVE_APP or WEBVIEW_com.example.app. |
| flowControl | FailureHandling | Optional | Specify failure handling schema to determine whether the execution should be allowed to continue or stop. |
On success, the log shows Switching to the context '<context name>' successfully. If the context cannot be found, the step fails with the message Unable to switch to the context '<context name>'.
Example​
You want to fill in a web form inside the WebView of a hybrid app, then return to the native screens:
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
'Start application on current selected device'
Mobile.startApplication(GlobalVariable.G_AndroidApp, false)
'Open the screen that shows the WebView'
Mobile.tap(findTestObject('Mobile/button_Open_Form'), 10)
'Switch to the WebView context'
Mobile.switchToContext('WEBVIEW_com.example.app')
'Work with the web page by using WebUI keywords'
WebUI.setText(findTestObject('Web/input_Email'), 'user@example.com')
WebUI.click(findTestObject('Web/button_Subscribe'))
'Switch back to the native context'
Mobile.switchToContext('NATIVE_APP')
'Close application on current selected device'
Mobile.closeApplication()