AppiumDriver not recognising the WebElements in WebView

Hi,

I am using Appium with Java client 1.5.0 and trying to automate an Hybrid app. When I launch the app, I am getting a NATIVE pop up with ok button. I am able to handle it by Switching to NATIVE_APP using driver.context(“NATIVE_APP”). Once I close the Native pop up, the webpage is getting loaded in the view and am trying to access it using,

Set<String> contextNames2 = driver.getContextHandles();
   for (String c : contextNames2) {
      if (c.contains("WEBVIEW")){
         System.out.println(c);
         driver.context(c);
      }
 }
//Not working
WebElement smartCardIn = driver.findElement(By.cssSelector("[data-ng-click='smartCardIn()']"));
smartCardIn.click();

By doing like I am able to switch to WEBVIEW context, but the next line where I am trying to access WebElement, is not working. Appium will wait for default next command, say 200 seconds and it will close the session. I have used Thread.Sleep(15000) before switching to WEBVIEW but still not success. And I also tried with different versions of Appium 1.3.4 and Appium 1.4.0 with Chromedriver 2.10, 2.14 and 2.15.
I am here by including the Appium server log.

Capabilities are set as follows,

    File appDir = new File("D:\\lzo_latest\\latest");
    File app = new File(appDir, "file name of apk");
    DesiredCapabilities capabilities = new DesiredCapabilities(DesiredCapabilities.android());
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("platformVersion", "4.4.2");
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("newCommandTimeout", 200);
    capabilities.setCapability("appPackage", "package name");
    capabilities.setCapability("noReset", true);
    capabilities.setCapability("appActivity", "main activity name");  
    capabilities.setCapability("autoWebviewTimeout", 200000);
    capabilities.setCapability("deviceReadyTimeout", 100);
    driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

Please help me in this regard.

Thanks
C.S Harsha

> info: [debug] [BOOTSTRAP] [debug] Element[] is null: (1)
> info: [debug] [BOOTSTRAP] [debug] getElements tmp selector:UiSelector[INSTANCE=1, RESOURCE_ID=android:id/button2]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":[{"ELEMENT":"1"}],"status":0}
> info: [debug] Responding to client with success:{"status":0,"value":````[{"ELEMENT":"1"}],"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: <-- POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/elements 200 107169.129 ms - 89 {"status":0,"value":[{"ELEMENT":"1"}],"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: --> POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/element {"using":"id","value":"android:id/button2"}
> info: [debug] Waiting up to 200000ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"android:id/button2","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":````{"strategy":"id","selector":"android:id/button2","context":"","multiple````":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding android:id/button2 using ID with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=android:id/button2]
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"2"},"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":````{"ELEMENT":"2"},"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: <-- POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/element 200 290.983 ms - 87 {"status":0,"value":{"ELEMENT":"2"},"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: --> POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/element/2/click {"id":"2"}
> info: [debug] Pushing command to appium work queue: ["element:click",{"elementId":"2"}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: click
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
> info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: <-- POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/element/2/click 200 3985.911 ms - 76 {"status":0,"value":true,"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: --> GET /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/contexts {}
> info: [debug] Getting a list of available webviews
> info: [debug] executing cmd: D:\Android_SDK\Android\ADT\sdk\platform-tools\adb.exe -s emulator-5554 shell "cat /proc/net/unix"
> info: [debug] WEBVIEW_3167 mapped to pid 3167
> info: [debug] Getting process name for webview
> info: [debug] executing cmd: D:\Android_SDK\Android\ADT\sdk\platform-tools\adb.exe -s emulator-5554 shell "ps"
> info: [debug] Parsed pid: 3167 pkg: com.csc.chmwardview.chndev
> info: [debug] from: u0_a56,3167,938,410256,124092,ffffffff,b765af1b,S,com.csc.chmwardview.chndev
> info: [debug] returning process name: com.csc.chmwardview.chndev
> info: [debug] Available contexts: NATIVE_APP
> info: [debug] ["WEBVIEW_com.csc.chmwardview.chndev"]
> info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.csc.chmwardview.chndev
> info: [debug] Responding to client with success: {"status":0,"value":["NATIVE_APP","WEBVIEW_com.csc.chmwardview.chndev"],"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: <-- GET /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/contexts 200 449.529 ms - 123 {"status":0,"value":["NATIVE_APP","WEBVIEW_com.csc.chmwardview.chndev"],"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: --> POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/context {"name":"WEBVIEW_com.csc.chmwardview.chndev"}
> info: [debug] Getting a list of available webviews
> info: [debug] executing cmd: D:\Android_SDK\Android\ADT\sdk\platform-tools\adb.exe -s emulator-5554 shell "cat /proc/net/unix"
> info: [debug] WEBVIEW_3167 mapped to pid 3167
> info: [debug] Getting process name for webview
> info: [debug] executing cmd: D:\Android_SDK\Android\ADT\sdk\platform-tools\adb.exe -s emulator-5554 shell "ps"
> info: [debug] Parsed pid: 3167 pkg: com.csc.chmwardview.chndev
> info: [debug] from: u0_a56,3167,938,410256,124092,ffffffff,b765af1b,S,com.csc.chmwardview.chndev
> info: [debug] returning process name: com.csc.chmwardview.chndev
> info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.csc.chmwardview.chndev
> info: [debug] ["WEBVIEW_com.csc.chmwardview.chndev"]
> info: [debug] Available contexts: NATIVE_APP,WEBVIEW_com.csc.chmwardview.chndev
> info: [debug] Connecting to chrome-backed webview
> info: Set chromedriver binary as: C:\Program Files\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
> info: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
> info: No old chromedrivers seemed to exist
> info: Spawning chromedriver with: C:\Program Files\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe --url-base=wd/hub --port=9515
> info: [CHROMEDRIVER STDOUT] Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 9515
> Only local connections are allowed.
> info: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
> info: Got response with status 200: {"sessionId":"","status":0,"value":{"build":{"version":"alpha"},"os":{"arch":"x86","name":"Windows NT","version":"6.1 SP1"}}}
> info: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.csc.chmwardview.chndev","androidUseRunningApp":true,"androidDeviceSerial":"emulator-5554"}}}
> info: Got response with status 200: {"sessionId":"6353c255554412d8830707cfd14743fb","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{},"cssSelect...
> info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: <-- POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/context 200 8453.876 ms - 76 {"status":0,"value":null,"sessionId":"5cc75973-8c25-4682-9309-a8ac377e5ee7"}
> info: --> POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/elements {"using":"css selector","value":"div.logo-nfc"}
> info: Proxying [POST /wd/hub/session/5cc75973-8c25-4682-9309-a8ac377e5ee7/elements] to [POST http://127.0.0.1:9515/wd/hub/session/6353c255554412d8830707cfd14743fb/elements] with body: {"using":"css selector","value":"div.logo-nfc"}
> info: [debug] Didn't get a new command in 200 secs, shutting down...
> info: Shutting down appium session
> info: [debug] Pressing the HOME button
> info: [debug] executing cmd: D:\Android_SDK\Android\ADT\sdk\platform-tools\adb.exe -s emulator-5554 shell "input keyevent 3"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Stopping chromedriver for context WEBVIEW_com.csc.chmwardview.chndev
> info: Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/6353c255554412d8830707cfd14743fb] with no body