# Android driver cannot identify web elements after switching to webview context

**URL:** <https://discuss.appium.io/t/android-driver-cannot-identify-web-elements-after-switching-to-webview-context/7603>\
**Category:** Issues/Bugs\
**Created:** [December 21, 2015, 10:50am UTC](https://discuss.appium.io/t/android-driver-cannot-identify-web-elements-after-switching-to-webview-context/7603 "2015-12-21T10:50:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hansiniej](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hansiniej](https://discuss.appium.io/u/hansiniej)\
**Post date:** [December 21, 2015, 10:50am UTC](https://discuss.appium.io/t/android-driver-cannot-identify-web-elements-after-switching-to-webview-context/7603/1 "2015-12-21T10:50:03Z")

</div>

I was trying to catch the username text box element in web view of a hybrid app.But when i run this code the test fails after switching to the web context and only identifies the logo. I used chrome inspect to identify web elements in the hybrid app.

WebDriverWait wait;  
wait = new WebDriverWait(driver,300);

```
  System.out.println(new Timestamp(new Date().getTime()) + ": Waiting for web view");
  wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("android.webkit.WebView")));
  System.out.println(new Timestamp(new Date().getTime()) + ": Wait ended");
  
  System.out.println(new Timestamp(new Date().getTime()) + ": Searching contexts");
  java.util.Set<String> contextNames = driver.getContextHandles();
  for (String contextName : contextNames) {
	  System.out.println("Context Found: [" + contextName + "]");
    if (contextName.contains("WEBVIEW")){
    	System.out.println(new Timestamp(date.getTime()) + ": Switching context - " + contextName);
    	driver.context(contextName);
   
    	System.out.println(new Timestamp(date.getTime()) + ": Switched to web context - " + contextName);
    	break;
    }
  }

  System.out.println(new Timestamp(new Date().getTime()) + ": Waiting for log in area to be visible");
  wait.until(ExpectedConditions.visibilityOf(driver.findElementById("logo-##")));
  System.out.println(new Timestamp(new Date().getTime()) + ": Login logo is visible");
  System.out.println(new Timestamp(new Date().getTime()) + ": Waiting for username textbox");

  wait.until(ExpectedConditions.visibilityOf(driver.findElementByClassName("username-##")));
  System.out.println(new Timestamp(new Date().getTime()) + ": Login username textbox found");

  driver.findElementByClassName("username-##").sendKeys("abc");
  driver.findElementByXPath("//*[@id=\"login-page\"]####").sendKeys("xyz");
  driver.findElementByXPath("//*[@id=\"button\##"]").click();

```

When i run the above script, the appium log showed an error as follows.

> info: Got response with status 200: {“sessionId”:“b2e632e71daeded7f80dd06e98b91716”,“status”:0,“value”:null}

---

<div class="post-metadata">

**Author:** ![amitjaincoer191](https://discuss.appium.io/user_avatar/discuss.appium.io/amitjaincoer191/32/5339_2.png) [@amitjaincoer191](https://discuss.appium.io/u/amitjaincoer191)\
**Post date:** [December 22, 2015, 1:09pm UTC](https://discuss.appium.io/t/android-driver-cannot-identify-web-elements-after-switching-to-webview-context/7603/2 "2015-12-22T13:09:50Z")

</div>

I am not sure with solution but I can suggest 2 things

1. first remove string quotes for attribute values u use in xpath  
driver.findElementByXPath("//\*[@id=‘login-page’]").sendKeys(“xyz”);

2. Try to use xpath given by chrome browser e.g. right click on element and on menu select copy xpath… if it works

[http://toolsqa.com/mobile-automation/appium/how-to-inspect-and-automate-webview-in-hybrid-app/](http://toolsqa.com/mobile-automation/appium/how-to-inspect-and-automate-webview-in-hybrid-app/)
