switchTo WebView in Hybrid iOS app

How to switch from a Native to WebView?When i use the below code:

String context=ElementsAction.driver.getContext();
System.out.println(“Context Name” +context);
//Here my Context is getting printed as NativeAPP

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

In the above code snippet,line 2 the Context gets printed as NativeAPP but i am trying to get the WEBAPP view,but that line 4 fails and throws below error message.

“An unknown server-side error occurred while processing the command. (Original error: connect ECONNREFUSED) (WARNING: The server did not provide any stacktrace information)”

Kindly help i am totally stuck.


1 Like

You need to switch context to WEBVIEW_1 specifically. Then remember to switch back to NATIVE_APP before interacting with any native elements. Note the specific spellings of the contexts. Also, pay attention to hybrid views, I have seen the index the WEBVIEW can change from WEBVIEW_1 to WEBVIEW_3 etc.


An unknown server-side error occurred while processing the command. (Original error: connect ECONNREFUSED) (WARNING: The server did not provide any stacktrace information)"

This error must coming up may be coz u are using a real ios device.
You will require to connect to proxy using : ios_webkit_debug_proxy -c UDID:27753
This should solve your problem.

@Mayuresh_Shirodkar yeah! iam using a real device,how should i connect to proxy?


In place i am not able to get the list of Context,then how will i switch to WEBVIEW?
Need support !

P.S.If any specific logs is required, i can post here

Try this it will solve ur problem:

Error: Could not connect to WebKitRemoteDebugger server.(ECONNREFUSED)

  1. install ios_webkit_debug_proxy
  2. Connect the device to the mac
  3. In the terminal,enter command ios_webkit_debug_proxy –c udid:27753
    At present Appium allows connection only at 27753 port. Also note that safari web inspector is enabled on the phone as well as on the desktop.

@Mayuresh_Shirodkar i will try these steps,thanks for ur help.

Before that i wanted to let u know that ,my app is hybrid ,will that have any intervention with safari?

Nope…Shouldn’t be a problem.

i tried installing ioS-webKit but got the below errors:

MACPC270917:~ 244325$ brew install ios-webkit-debug-proxy
-bash: brew: command not found

i even tried the below but its prompting for a password and when i give password,it throws error

MACPC270917:~ 244325$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
==> This script will install:
==> The following directories will be made group writable:
==> The following directories will have their group set to admin:

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/man /usr/local/share/man/man1
Sorry, try again.
Sorry, try again.
Sorry, try again.
sudo: 3 incorrect password attempts
Failed during: /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/man /usr/local/share/man/man1
MACPC270917:~ 244325$

Kindly help

Thanks @Mayuresh_Shirodkar in getting this done.

Now i have got my webview by running this code :

      Set<String> getCont=ElementsAction.driver.getContextHandles();
		for(String switchCont:getCont)
			System.out.println("get" +getCont);

Here it prints NATIVEAPP and WEBVIEW_1


But every time i run my app the WEBVIEW_1 is changing/incrementing [i.e WEBVIEW_1 then WEBVIEW_2 then WEBVIEW_3]

So my switch is not happening everytime…

This will be an issue.You will need to use methods like contains,matches if using java.

1 Like

@Mayuresh_Shirodkar yeah im using contains and now iam able to proceed further … Thanks alot for your support…

Will get back to you if i have any issues… Thanks alot again making me cross this overhead.

1 Like

ElementsAction - Where u got this one? how can we declare the elements?

That is a separate class holding all the functions.
Its actually my framework design… nothing much