Solving Element Visibility Issues in Appium for iOS

Solving Element Visibility Issues in Appium for iOS

21 May 2024 Stephan Petzl Leave a comment Tech-Help

When working with Appium to automate testing for iOS applications, you may encounter issues where elements that are visible in the Appium Inspector are not found or are reported as invisible when accessed through the Python Appium client. This article will guide you through troubleshooting and resolving these issues.

Understanding the Problem

Let’s consider the following scenario:

  • Appium Version: 1.5.0
  • Xcode Version: 7.3
  • iOS Version: 10.11.4 OSX EI Capitan
  • Simulator: iOS 8.1

The XML structure of your application may look something like this:

      <?xml version="1.0" encoding="UTF-8"?>
                  <UIAImage name="icon-menu-logo.png" visible="false"></UIAImage>
                  <UIAStaticText visible="false"></UIAStaticText>
                      <UIATableCell name="MARKETS" visible="false">
                          <UIAStaticText name="MARKETS" visible="false"></UIAStaticText>
                  <UIANavigationBar name="AUDIT TRAIL" visible="true">
                      <UIAButton name="icon nav menu" visible="true"></UIAButton>

In the Appium Inspector, using .tableViews()[1].cells() returns the rows correctly. However, in the Python Appium client, the same code may return elements with visibility set to false and size/location as zero.

Solution: Avoid Duplicate Keys

One effective solution to this problem is to ensure that there are no duplicate keys within the XML structure. Duplicate keys can significantly impact the reliability of locating elements. This approach has been suggested and has shown improvements in the reliability of finding required elements.

Steps to Avoid Duplicate Keys

  • Review your XML structure to identify any duplicate keys.
  • Modify the keys to ensure they are unique.
  • Test the changes in the Appium Inspector and Python Appium client.

Implementing the Solution

To implement this solution, follow these steps:

  1. Open your XML file and search for elements with the same name or attribute values.
  2. Change the name or attribute values to ensure uniqueness. For example, if you have multiple <UIAStaticText name="MARKETS"> elements, modify them to something like <UIAStaticText name="MARKETS_1"> and <UIAStaticText name="MARKETS_2">.
  3. Save the changes and re-run your tests in both the Appium Inspector and the Python Appium client to verify that the elements are now being correctly identified.

Advanced Solutions

If the issue persists, consider exploring more advanced solutions such as:

Enhancing Your Testing Workflow with Repeato

For those seeking a more efficient and reliable testing solution, consider using Repeato. Repeato is a no-code test automation tool for iOS and Android that helps you create, run, and maintain automated tests for your apps. Unlike traditional tools such as Appium, Repeato is particularly fast to edit and run tests, leveraging computer vision and AI to ensure stability and speed.

With Repeato, you can:

  • Create tests quickly without writing code.
  • Run tests blazingly fast.
  • Maintain test stability with AI-based element recognition.

Learn more about how Repeato can transform your testing workflow by visiting our Getting Started page.

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