I am testing a native app in appium and i’d like to test a part in the app where it redirects into a webview.
In the appium inspector i can see the objects in the webview but can’t click on them.
In the inspector i see only “no context” and can’t switch to a webview context like the tutorial explains.
When i try to use driver.getContextHandles() i get an exception.
What can i do in order to test the webview part in my app?
/* Code for context to find the View used in application */
Set contextNames = Appiumsetup.driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains(“WEBVIEW”)){
Appiumsetup.driver.context(contextName);
}
}
@Manish_Birthariya
The post i wrote initially relates to switching from native view to webview.Most of the test is executed on a native app when a certain action loads a webview.
Maybe you mean that when i open a web view i should start a second driver and close it when i am back to the native view? that’s interesting…Also , i don’t know if there is a difference but i am writing for iOS right now.
unable to switch to Webview with appium version 1.4.11 or 1.4.12 when test with hybrid apps on Android 4.4.2 or 5.0.1
any idea ? is it the bug in this release?
info: [debug] Getting a list of available webviews
info: [debug] executing cmd: C:\Users\xxxx\AppData\Local\Android\sdk1\platform-tools\adb.exe -s
05e1839607a3b748 shell “cat /proc/net/unix”
info: [debug] Available contexts: NATIVE_APP
info: [debug] []
info: [debug] Available contexts: NATIVE_APP
info: [debug] Responding to client with error: {“status”:35,“value”:{“message”:“No such context foun
d.”,“origValue”:“Context ‘WEBVIEW_1’ does not exist”},“sessionId”:“7bf2552a-995f-402e-ab71-26d4e25ab
f95”}
I am using appium version 1.4.14 to test a hybrid app developed by Ionic. The same error message shows up when switching to webview action is executed:
nfo: [debug] Getting a list of available webviews
info: [debug] executing cmd: /Users/gr_haonan/Library/Android/sdk/platform-tools/adb -s 73f50e0d shell “cat /proc/net/unix”
info: [debug] Available contexts: NATIVE_APP
info: [debug] []
info: [debug] Available contexts: NATIVE_APP
info: [debug] Responding to client with error: {“status”:35,“value”:{“message”:“No such context found.”,“origValue”:“Context ‘WEBVIEW_1’ does not exist”},“sessionId”:“0d4ff72b-8084-4546-ba8b-e2311ed05474”}
the code in python is in below as copied from the appium document:
context_name = “WEBVIEW_1”
driver.switch_to.context(context_name)
Hi,
Please make sure that the version of selenium-server-standalone, selenium-java, java-client.
I used them as below:
selenium-server-standalone-2.48.2.jar
selenium-java-2.48.2.jar
java-client-3.2.0.jar
My code as below:
protected void switchToWebview() throws Exception {
// E.G.['NATIVE_APP', 'WEBVIEW_1', ...]
Set<String> contexts = driver.getContextHandles();
// make sure we have something other than the native context
// assertThat(contexts.size(), greaterThan(1));
for (String context : contexts) {
// System.out.println(contexts);
if (!context.equals("NATIVE_APP")) {
driver.context((String) contexts.toArray()[1]);
break;
}
}
System.out.println("execute context switch successfully!!! "
+ contexts.toArray()[1]);
}
@liucong_3689 I am also trying to automate hybrid iOS app build in ionic using appium only. Using c# for coding, I am able to switch the context but I am not able to identify elements after that. Have you got any solution for this or you made progress on this one.
I am using Appium 1.5 for Android.
I am able to successfully switch context to webview and interact with webview element ( my test broke previously when upgraded to 1.4 , 1.5 ) Heres the fixed snippet:
def switch_to_webview(driver):
if not driver.context or driver.context == "NATIVE_APP":
debug_log(“print your available contexts: .................... %s”, driver.contexts)
switchto = driver.contexts[0] //point to the index of your webview
driver.switch_to.context(switchto)
else:
debug_log("no need to switch")
self.webview = lambda: self.driver.find_element_by_id("webview")
self.webview()
switch_to_webview(self.driver)
I was automating an hybrid app, while switching, it only shows name of native context. WebView Context is shown as webview_undefined. So how can I get all the webview context names ? pls help soon