Not able to identify element in WEBVIEW in iOS hyprid app(build in Ionic) automation using Appium on real device

I was trying to automate the hybrid app build using ionic2/Angular2 and typescript.
I am using C# for code writing. test are in BDD - specflow Versions: iOS:9.3.1 Xcode: 7.3 Appium: 1.4.13

I am not able to identify elements after swtiching Context to WEBVIEW.

Calling IOSDriver using below code

private IOSDriver driver = null;

public IOSDriver GetDriver(string platformVersion, string deviceName, string udid ,string appPath, string serverUri)
Capabilities iosCapabilities = new Capabilities();
DesiredCapabilities capabilities = iosCapabilities.Get(platformVersion, deviceName, udid, appPath);
driver = new IOSDriver(new Uri(serverUri), capabilities, TimeSpan.FromSeconds(Constants.DriverWaitTime));
driver.Manage ().Timeouts ().ImplicitlyWait (TimeSpan.FromSeconds(Constants.ImplicitWaitTime));

var contextNames = driver.Contexts;
driver.Context = contextNames[1];


Setting Capabilities as

private DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.SetCapability (“appium-version”, Constants.AppiumVersion);
capabilities.SetCapability (“platformName”, Constants.PlatformName);
capabilities.SetCapability(“autoWebView”, “true”);
capabilities.SetCapability(“browserName”, “iOS”);
capabilities.SetCapability (“platformVersion”, Constants.PlatformVersion);
capabilities.SetCapability(“deviceName”, deviceName);
capabilities.SetCapability(“app”, appPath);
capabilities.SetCapability(“udid”, udid);

Am I setting the capabilities in correct way?

Solution tried:

  1. I checked using browserName capbility as blank/safari but didn’t worked
  2. Also, I installed ios-webkit-debug-proxy and started proxy using terminal in background on my mac

Problem is I am not able to identify elements in WEBVIEW even after switching the context.

My Observation:->

After launching the app, in appium inspector I am able to see all the elements and I am trying to click on textbox to enter some value

Xpath of textbox(as i can view in appium inspector window):

var contextNames = driver.Contexts

is giving me list to views(In my case 2 views: NATIVE_APP, WEBVIEW_1) WebView context is dynamically updating from 1,2,3 and so on…

As soon as I call

diver.Context=contextNames[1]; //setting context to WEBVIEW

and refresh the appium inspector I am not able to see/identify single element.Everything goes away.

Why I am not able to see/identify elements after switching to webview. (Note: As soon as I Switch back to driver.Context=“NATIVE_APP” every element becomes visible in appium inspector but still I am not able to click)

Error is thrown as: “An element could not be located using given search parameter”

Manually also when I try to tap or sendkeys using appium inspector it is not letting me do so(after lauching tha app manually using inspector button). What is the issue here. Help would be highly appreciated

Error message as in appium window:

Error log on Appium Logs(Not able to view elements in WEBVIEW after switching context

Do verify the capabilities which I am using before switching the context. Thanks in advance

You should take locators for webview elements in Safari, just go to [localhost:port] (where port is ios webview debug proxy port for this device)

@1113 I tried doing that also, but no luck so far :frowning:

Hi Suraj,

Launch the safari browser in mac PC in menu you should have Develop options.
Click on the Develop option in that list it should list the your device.

Select your device -> web page. (it show’s only if web page is open in phone). you will able to locate the web elements.

If you don’t see the Develop menu in the menu bar, choose Safari >
Preferences, click Advanced, then select “Show Develop menu in menu bar.”

Look for how to switch the webview and you need to run the ios_webkit_debug_proxy.

Hope this will help you.


Hi Naresh,

I did all these above steps but no help.

After setting the capabilities and launching the app I am not able to see index.html page in my safari if I use autoWebView, true in my capability

I am getting strange behaviour, If I am not using autowebview and then lauching the app then I am able to see index.html page. I suppose Appium is considering and taking my app as native app.

I even double checked this using

driver.Context=“NATIVE_APP”; // index.html visible
driver.Context=“WEBVIEW_1”; //index.html becomes disabled and not able to click on that

Even checked through localhost:27753 and the same behaviour.

When I force appium to switch context to webview and then click it just passes that step without doing any event(click/sendkeys)

and in native view it was showing error:

info: atom did not return yet, checking to see if we are blocked by an alert
info: Pushing command to appium work queue: “au.alertIsPresent()”

and it returns 8 commands found au.alertIsPresent()

Check capabilities settings.

browser Name Safari but you gave IOS and it should be platformversion not the plaftormName.
problem may be with capabilities.

Try to print the webview before switching after switching.

For hybrid app do I need to add browserName capabilities

I am using
capabilities.SetCapability (“appium-version”, “1.4.13”);
capabilities.SetCapability (“platformName”, “iOS”);

Am I using correct capabilities??

In addition to above two capabilities I am using below once also
capabilities.SetCapability(“autoWebview”, “true”); // should I define true as boolean or string(in quotes)
capabilities.SetCapability (“platformVersion”, “9.3”);
capabilities.SetCapability(“deviceName”, “iPad Air”);
capabilities.SetCapability(“app”, “”);
capabilities.SetCapability(“udid”, “”);

Try with out setting this capability. and make sure that your are running the webkitproxy server
capabilities.SetCapability(“autoWebview”, “true”);

Tried but not working still :frowning:

can you copy paste all the capabilities? may be your making mistake in that.

capabilities.SetCapability (“appium-version”, “1.4.13”);
capabilities.SetCapability (“platformName”, “iOS”);
capabilities.SetCapability(“autoWebview”, “true”); // should I define true as boolean or string(in quotes)
capabilities.SetCapability (“platformVersion”, “9.3”);
capabilities.SetCapability(“deviceName”, “iPad Air”);
capabilities.SetCapability(“app”, “”);
capabilities.SetCapability(“udid”, “”);

I was finding the solution and came across some articles where protractor + APpium is used for automation of ionic app.

Mine is also same. Can’t we automate ionic app only using Appium.

Is it possible that Appium is not able to identify Ionic html tags??

Hope you are using the hybrid app ? try adding this cap.
capabilities.setCapability(“appPackage”, “xxxxxxxxxxxxxx”);

What is the advantage of having private obj ?
private IOSDriver driver = null;
private DesiredCapabilities capabilities = new DesiredCapabilities();

Yes I am using hybrid ionic iOS app. Defined them private since I don’t want to use them outside the class.

Does appPackage is required for ios automation?

yes its compulsory, Read the document carefully provided by Appium.

I read and found appPackage is required only for Android on link. If you have any other reference, please do share.

I am facing same issue . the element is present in Android but same element could not find in
iOs how to resolve this issue.

@dhanu1 kindly ellaborate… what is xpath/environment/capabilities … This would help to resolve ur issue

element is overlapp in frame so finding element is difficult .plz tell me how to find element.
MobileElement el8 = (MobileElement) driver.findElementByAccessibilityId(“et_lighton”);;

I face the same problem … I’m using ruby.
I have a popup that can not click at all. Application developed in IONIC (latest version).

My ENV.RB is like this … I’ve tried several ways

Before do
def caps
caps: {
deviceName: ‘0029179798’, # ‘emulator-5554’ Motorola Moto Z Play
platformName: ‘Android’,
#apk: (File.join(File.dirname(FILE), ‘app-intelbras.apk’)),
appPackage: ‘io.ionic.starter’, #com.ioasys.appprova / io.ionic.starter
appActivity: ‘io.ionic.starter.MainActivity’, #com.appprova.core.activity.OnBoardingActivity" / io.ionic.starter.MainActivity
newCommandTimeout: ‘3600’,
platformVersion: ‘8.0.0’, #‘8.1.0’
appiumVersion: ‘1.8.1’,
deviceOrientation: ‘landscape’, #portrait
autoWebview: true,
# chromedriverExecutable: ‘C:/projetos/desenvolvimento/tools/drivers/chromedriver_2.41/chromedriver.exe’,
androidScreenshotPath: ‘results/screenshots’,
nativeWebScreenshot: true,
# chromedriverUseSystemExecutable: false,
autoGrantPermissions: true,
browserName: ‘’ #Deve usar uma string vazia se estiver automatizando um aplicativo
appium_lib: { server_url:SERVER_URL, port:PORT }

Hi all,

I am also facing the same issue. Unable to switch to Webview from Native app in IOS. Scroll in IOS also not working.
Doing IOS automation with xFramium tool+Appium+IOS.
“deviceName”: “iphone X”,
“udid”: “**",
“platformName”: “IOS”,
“platformVersion”: “11.4”,
“bundleId”: "
“automationName”: “XCUITest”
“browserName”: “Safari”,
“startIWDP”: “true”,
“autoWebview”: “true”,
“absoluteWebLocations”: “true”

xFramium-Appium capabilities

iphone X IOS false

<capability name=“appPackage” class="STRING”>
<capability name=“bundleId” class="STRING”>

Could anyone help out from this issue.