2

I was trying to automate tests for a hybrid app, while switching, it only shows name native context. WebView Context is shown as webview_undefined.

Set<String>  contextNames = driver.getContextHandles();
for (String contextName : contextNames) 
{
     System.out.println(contextName);
     if (contextName .contains("WEBVIEW"))
     {
         driver.context(contextName); 
        webViewFound = true; 
        System.out.println("switched to webview");
    }
}

I'm using the above code. Can anyone give solution for this !

1 Answer 1

1

Dinesh, Give a try to below snippet

Set <String> handles =driver.getWindowHandles();
Iterator<String> it = handles.iterator();

String parent = it.next();
String child = it.next();

driver.switchTo().window(child);
//perform actions on child window

driver.close(); // only for child wondow


driver.switchTo().window(parent);
//perform actions on parent window

driver.quit(); // After execution of main thread and for parent window

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.