Switching to a Dynamically Named Context Handle with Appium and Java

Kevin Berg
1 min readAug 12, 2016

--

Wow. Looking back at the title, this is a very specific blog post. I was tasked with helping with some Appium native app tests last week where the context changed for each app installation or session. This is a common action in many Appium tests when one needs to switch from the native app to the browser to verify certain activities, e.g. clicking on an advertisement.

Every time I ran a test and tried to switch from the NATIVE_APP to the WebView, I was unable to because the name of the WebView was always different.

Here is how I was able to solve this issue:

Now it will be set to the second context in the list. Hopefully this saves time for some folks that run in to a similar problem.

--

--