Webview access in android appium automation

I am using the following code to access the webview but it always returns NATIVE_APP. Am I missing anything. Any suggestions are appreciated. Platform version 4.4, API level 19

	    Set<String> contextNames = driver.getContextHandles();
	    for (String contextName : contextNames) {
	    	if (contextName.contains("WEBVIEW")){

You mean the call to getContextHandles only returns NATIVE_APP and no other contexts? Are you sure a webview is located on your app?

Yes call to getContextHandles only returns NATIVE_APP. My app opens the facebook login page in a browser. Do I need to change any setting in phone. I am using android phone and I have selected stay awake and use debugging options.

Ah, webviews inside your app are different from opening up the browser while your app is running. Unless you open the browser using appium, it isn’t set up to automate the new browser activity.

So what is the option to test it. Will Selendroid work

At this point no changes is allowed in my application. What are the options to test the hybrid android app. This is a roadblock for me

It’s not that it’s a hybrid app, appium handles hybrid apps fine. The issue is you are opening the Facebook app, which we cannot automate since it wasn’t started by appium.

I think there is a confusion here. My app is not opening another app its opening facebook page in a browser

Browser is a different application.
Hybrid in terms of Appium means opening browser content as a webview within your application.

1 Like

Ok.May be confusion in my end.
When I view it in Appium inspector Facebook page is opened in webkit.webview. Is it a different application?
In IOS facebook is opened in UIWebview and I could able to get the contexts without any issues.

if you can just add setWebContentsDebuggingEnabled for webview in your app

I want ho content of webview but i don’t know how to access webview in android Native app. I have write following code …Please help me

public void WebviewHandle() throws InterruptedException
driver.findElementByXPath("//*[@class=‘android.widget.ImageButton’ and @content-desc=‘Navigate up’]").click();
Set contextNames = driver.getContextHandles();
for(String context : contextNames) {
System.out.println("Context Name is " + context);


I am stuck in How to assert Toast message???

Click Facebook login button which is native :

Switch to webview context :

//here we getting the list of context
Set<String> contextHandles = wd.getContextHandles();
for (String s : contextHandles) {
System.out.println("Context : " + s);
//if context contains webview then set the webview context
if (s.contains("WEBVIEW")) {

Do Facebook Login Flow in webview :

wd"//input[@name='pass']"".findElement(By.xpath()).sendKeys(<your_password>"); // test password
WebDriverWait driverWait = new WebDriverWait(wd, 10);
driverWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@name='__CONFIRM__']"))); // waiting for the element to be clickable
System.out.println(wd.getPageSource()); // get the page source 
wd.findElement(By.pathx("//button[@name='__CONFIRM__']")).click(); //  this step login process is done.

Come back to Native view :

// here i need to get the context again
Set<String> contextHandles2 = wd.getContextHandles();
for (String s : contextHandles2) {
System.out.println("Context : " + s);
if (s.contains("NATIVE_APP")) {

Youtube video : https://www.youtube.com/analytics?o=U#dt=nt,fe=17092,fr=lw-001,fs=17065;fc=0,fcr=0,fi=v-AcBzbhQgDis,r=realtime,rsc=2