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}