[Appium][Android] Change window/tab in a chrome custom tab

A chrome custom tab is a chrome browser instance on an Android device. Appium tries to get available contexts by checking browser/webview processes on the device/application. It means even when the chrome custom tab has multiple tabs/windows, Appium probably can find a chrome instance (process) and attach to it.

To switch to another tab on the chrome instance, you need to manage the session as a general WebDriver browser inside WebView context in Appium.

For example, when you have a a window_handle name named tab inside the chrome instance, you can switch to the tab below. (in Ruby)

# Change the context to WebView (Attach to chromedriver session)
driver.set_context('WEBVIEW_XXXX')

# Get available tabs/windows int he chrome instance
driver.window_handles

# Change the tab/window in the "chrome" instance
driver.switch_to.window('a window_handle name')

It requires an extra step, but newer chrome browsers (and custom tab) behave so.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.