Skip to main content

[Mobile] Get Contexts

Last updated: October 2026

Description​

Get the names of all contexts available in the current mobile session. Every mobile app has the NATIVE_APP context. A hybrid app also has one or more WebView contexts, such as WEBVIEW_<app package> on Android or WEBVIEW_<number> on iOS.

Use this keyword to find a WebView context at run time, then switch to it with Mobile.switchToContext. Search the list by name, not by position: the number and order of contexts can vary, for example when the app shows more than one WebView.

Keyword name: Mobile.getContexts

Parameters​

ParameterParameter TypeRequiredDescription
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop.

Returns​

Parameter TypeDescription
List<String>The names of all contexts available in the current mobile session, for example [NATIVE_APP, WEBVIEW_com.example.app].

If Katalon Studio cannot get the contexts, the step fails with the message Unable to get the context list.

Example​

You want to find the WebView context of a hybrid app and switch to it:

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.util.KeywordUtil
import internal.GlobalVariable as GlobalVariable

'Start application on current selected device'
Mobile.startApplication(GlobalVariable.G_AndroidApp, false)

'Get the names of all available contexts'
List<String> contexts = Mobile.getContexts()
KeywordUtil.logInfo('Available contexts: ' + contexts)

'Find the WebView context and switch to it'
String webViewContext = contexts.find { it.startsWith('WEBVIEW') }
Mobile.switchToContext(webViewContext)

'Switch back to the native context'
Mobile.switchToContext('NATIVE_APP')

'Close application on current selected device'
Mobile.closeApplication()

find returns null when no context name starts with WEBVIEW, for example when the WebView has not loaded yet. Check the value before you switch, or Mobile.switchToContext fails with Unable to switch to the context 'null'.

See also​

Was this page helpful?