No Action is performed after switching from Native to Webview

Hi All,

After I switch my Hybrid app from native view to web view no actions are performed.

Below is my code.

@Test
public void okbutton() throws InterruptedException, MalformedURLException {
caps = new DesiredCapabilities();
caps.setCapability(“deviceName”, TestBase.propertyValueCall(“deviceName”));
caps.setCapability(“platformVersion”, “8.1.0”);
caps.setCapability(“platformName”, TestBase.propertyValueCall(“platformName”));
caps.setCapability(“skipUnlock”, “true”);
caps.setCapability(“browserConnectionEnabled”, “true”);
caps.setCapability(“appPackage”, TestBase.propertyValueCall(“appPackage”));
caps.setCapability(“appActivity”, TestBase.propertyValueCall(“appActivity”));
caps.setCapability(“androidInstallTimeout”, 150000);
caps.setCapability(“autoGrantPermissions”, true);
caps.setCapability(“autoWebview”, “true”);
caps.setCapability(“chromedriverExecutable”,
“C:\Users\Dell\AppData\Roaming\npm\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe”);
driver = new AndroidDriver(new URL(“http://0.0.0.0:4723/wd/hub”), caps);
System.out.println("Value of driver is : " + driver);

Set contextNames = driver.getContextHandles();
System.out.println(contextNames.size());
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.toString().toUpperCase().contains(“WEBVIEW”)) {
driver.context(contextName.toString());
break;
}
}
Thread.sleep(5000);
driver.findElement(By.xpath("//div[@id = ‘idButton’]")).click();
}

Kindly guide me in fixing this issue asap.

Thanks,
Shenilton RamaKrishnan