Adding Accessibility Identifiers to iOS WebView (Cordova) in HTML

Adding Accessibility Identifiers to iOS WebView (Cordova) in HTML

21 May 2024 Stephan Petzl Leave a comment Tech-Help

Automating iOS webview apps using Appium can sometimes pose challenges, especially when it comes to identifying elements within the WebView. This article provides a clear guide on how to add accessibility identifiers to your iOS WebView application built with Cordova, making it easier for Appium to inspect and interact with these elements.

Understanding the Problem

When working with native apps, adding accessibility identifiers is straightforward. However, with webview apps, it can be less intuitive. The main issue arises when Appium Inspector fails to recognize the ID attributes of the elements. This is where adding specific accessibility attributes becomes crucial.

Solution: Adding Accessibility Attributes

To make elements in your webview app identifiable by Appium, you can add the aria-label and role attributes to the HTML elements. Here’s a simple example:


<div aria-label="your_accessibility_id" role="your_accessibility_id">
</div>
  

By including these attributes, Appium will be able to recognize and interact with the elements more effectively. This solution has proven to be effective and can save significant time during the automation process.

Practical Example

Consider a scenario where you have a button in your webview app that you want Appium to interact with. You can modify the button element as follows:


<button aria-label="submit_button" role="button">Submit</button>
  

In this example, the aria-label is set to “submit_button” and the role is set to “button”. This makes the button easily identifiable by Appium.

Additional Resources

For more detailed guidance on setting up and configuring Appium, you can refer to our comprehensive guides:

Enhancing Test Automation with Repeato

While Appium is a powerful tool, it can sometimes be slow and tests can become unstable. This is where Repeato comes in. Repeato is a no-code test automation tool for iOS and Android that leverages computer vision and AI to create, run, and maintain automated tests quickly and efficiently. Repeato tests are not only faster to create but also run significantly faster, providing a more stable and efficient testing experience.

By incorporating Repeato into your test automation strategy, you can streamline your testing process and ensure more reliable results.

Like this article? there’s more where that came from!