How to switch driver from hybrid to webpage

Hi,

First of all thanks to Appium for providing automation tool.

Do we have switching driver between native app and webpage.

Suppose i have launched app click on url links, then it will open separate web pages , so we will able to switch the driver to webpage and perform some action and come back to native app. Is it possible ?

Please provided the solution for this above issue.

Thanks & Regards
Naresh

for moving to webview use below code

Set contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1

      }
      driver.context("packagename");
      //driver.switchTo().window("WEBVIEW_0");
      }

and for moving to native

Set<String> contextNames = driver.getContextHandles();
      for (String contextName : contextNames) {
          System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1
          
      }
      driver.context("NATIVE_APP");
      //driver.switchTo().window("WEBVIEW");
      }

Hi Yogendra.

Thanks for your response, already tried that peace of code but it did not helped.

do we need any kind of settings ?

Thanks & Regards
Naresh

Set contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1

first prinf this…then use print matrial in

      driver.switchTo().window("print matrial");

Hi Yogendra,

Still driver does not switching to browser.

driver.context(“WEBVIEW_1”); This api does not throw any exception but how to conform driver as switched to safari browser .
after executing this driver.context facebook url opens in browser.
trying to enter the username and password.

driver.switchTo().window(“WEBVIEW_1”); this always throws exception

I am running the proxy webkit server in ternimal.
ios_webkit_debug_proxy -c 13a322d01627e6655e895e7c2c599b51b1c6049f:27753 -d

-----------Please refer to Appium Log------

info: <-- GET /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/contexts 200 70.382 ms - 122 {“status”:0,“value”:[“NATIVE_APP”,“WEBVIEW_1”,“WEBVIEW_2”,“WEBVIEW_4”],“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: --> POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context {“name”:“NATIVE_APP”}
info: [debug] Attempting to set context to ‘NATIVE_APP’
info: [debug] Responding to client with success: {“status”:0,“value”:"",“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: <-- POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context 200 9.471 ms - 74 {“status”:0,“value”:"",“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: --> POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context {“name”:“WEBVIEW_1”}
info: [debug] Attempting to set context to ‘WEBVIEW_1’
info: [debug] [REMOTE] Debugger web socket connected to url [ws://localhost:27753/devtools/page/1]
info: [debug] Responding to client with success: {“status”:0,“value”:“WEBVIEW_1”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: <-- POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context 200 95.952 ms - 83 {“status”:0,“value”:“WEBVIEW_1”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: --> POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context {“name”:“WEBVIEW_2”}
info: [debug] Attempting to set context to ‘WEBVIEW_2’
info: [debug] [REMOTE] Disconnecting from remote debugger
info: [debug] [REMOTE] Debugger web socket connected to url [ws://localhost:27753/devtools/page/2]
info: [debug] Responding to client with success: {“status”:0,“value”:“WEBVIEW_2”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: <-- POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context 200 129.142 ms - 83 {“status”:0,“value”:“WEBVIEW_2”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: --> POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context {“name”:“WEBVIEW_4”}
info: [debug] Attempting to set context to ‘WEBVIEW_4’
info: [debug] [REMOTE] Disconnecting from remote debugger
info: [debug] [REMOTE] Debugger web socket connected to url [ws://localhost:27753/devtools/page/4]
info: [debug] Responding to client with success: {“status”:0,“value”:“WEBVIEW_4”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: <-- POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context 200 16.207 ms - 83 {“status”:0,“value”:“WEBVIEW_4”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}

info: --> POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context {“name”:“WEBVIEW_1”}

info: [debug] Attempting to set context to ‘WEBVIEW_1’
info: [debug] [REMOTE] Disconnecting from remote debugger
info: [debug] [REMOTE] Debugger web socket connected to url [ws://localhost:27753/devtools/page/1]
info: [debug] Responding to client with success: {“status”:0,“value”:“WEBVIEW_1”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: <-- POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/context 200 35.273 ms - 83 {“status”:0,“value”:“WEBVIEW_1”,“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.4.13”,“revision”:“c75d8adcb66a75818a542fe1891a34260c21f76a”},“isShuttingDown”:false},“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}
info: <-- GET /wd/hub/status 200 3.191 ms - 179 {“status”:0,“value”:{“build”:{“version”:“1.4.13”,“revision”:“c75d8adcb66a75818a542fe1891a34260c21f76a”},“isShuttingDown”:false},“sessionId”:“99999b19-c716-4b42-b6dd-e98cda9c6f85”}

info: --> POST /wd/hub/session/99999b19-c716-4b42-b6dd-e98cda9c6f85/element {“using”:“name”,“value”:“email”}

info: [debug] Waiting up to 0ms for condition
info: [debug] [REMOTE] Executing ‘find_element’ atom in default context
info: [debug] [REMOTE] Sending javascript command
info: [debug] [REMOTE] Remote debugger data sent [{“method”:“Runtime.evaluate”,“params”:{“objectGroup”:“console”,“includeCommandLineAPI”:true,“doNotPauseOnExceptionsAndMuteConsole”:true,“expression”:"(function(){return function(){function h(a){return…]

Thanks for your help in advance.