[iOS] [C#] After updating from appium 1.6.0 to 1.6.2, I can no longer find elements the same way

Note: This is for automation on iOS using XCode 8.1 and iOS 10.1
I have this method that I use to grab an element at a given index:

public IWebElement GetProductElement(int index)
{
    try
    {
        return driver.FindElement(By.XPath(
            string.Format("//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]" + 
            "/XCUIElementTypeOther[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]" +
            "/XCUIElementTypeOther[1]/XCUIElementTypeTable[1]/XCUIElementTypeCell[{0}]", index)));
    }
    catch (Exception e)
    {
        Debug.WriteLine("Failed to GetProductElement(" + index + ") in " + this.ToString());
        throw e;
    }
}

This worked when I was using Appium 1.6.0 and since the upgrade, I get the following error when it tries to find elements using this method:

XCTRunner[1068]: Enqueue Failure: UI Testing Failure - Failure fetching attributes for element <XCAccessibilityElement: 0x608000248a30> Device element: Error Domain=XCTestManagerErrorDomain Code=13 "Error copying attributes -25202" UserInfo={NSLocalizedDescription=Error copying attributes -25202} <unknown> 0 1

I can go back to 1.6.0 for the time being, but I don’t want to be forced to use an older version if I don’t have to. Any help would be appreciated.

1 Like

@Blinkk please file this under https://github.com/appium/appium/issues

Done. https://github.com/appium/appium/issues/7444

Note: @VikramVI I logged the issue as you can see above but I have closed it as duplicates existed. My problem still exists though and still would like some discussion.

I am able to locate and interact with an element using a custom method in one area of the application I am testing, but receive an error using an almost identical method in other parts of the application. Here is the method that works:

public IWebElement GetMenuElement(int index)
{
    try
    {
        return driver.FindElement(By.XPath(
            string.Format("//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]" +
            "/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]" +
            "/XCUIElementTypeTable[1]/XCUIElementTypeCell[{0}]/XCUIElementTypeButton[1]", index)));
    }
    catch (Exception e)
    {
        Debug.WriteLine("Failed to GetMenuElement(" + index + ") in " + this.ToString());
        throw e;
    }
}

This selects a button from a small list of buttons within a hamburger menu and does so flawlessly. The following method attempts to do essentially the same thing (however, in a larger list of elements) and throws an error.

public IWebElement GetProductQuickCartElement(int index)
{
    try
    {
        return driver.FindElement(By.XPath(
            string.Format("//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]" +
            "/XCUIElementTypeOther[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]" +
            "/XCUIElementTypeOther[1]/XCUIElementTypeTable[1]/XCUIElementTypeCell[{0}]/XCUIElementTypeButton[1]", index)));
    }
    catch (Exception e)
    {
        Debug.WriteLine("Failed to GetProductQuickCartElement(" + index + ") in " + this.ToString());
        throw e;
    }
}

Here is the error I am receiving:

XCTRunner[1068]: Enqueue Failure: UI Testing Failure - Failure fetching attributes for element <XCAccessibilityElement: 0x608000248a30> Device element: Error Domain=XCTestManagerErrorDomain Code=13 "Error copying attributes -25202" UserInfo={NSLocalizedDescription=Error copying attributes -25202} <unknown> 0 1

A full copy of the test logs can be seen here. Note that at line 496 it successfully uses the first method to locate an element.

I have tried using the workarounds mentioned here: https://github.com/facebook/WebDriverAgent/issues/372 and https://github.com/facebook/WebDriverAgent/pull/369; and while changing the XCUIElement+FBIsVisible.m file to always return NO eliminated the error, the driver was still unable to find the element and got stuck in a loop of POST requests.

I would appreciate any help anyone may be able to offer in this area because while I have ways of working around this, these methods speed up my tests significantly (which is why I created them) and I would like to be able to continue using them.

@Blinkk this looks like a real bug, may be adding all these details to https://github.com/facebook/WebDriverAgent/issues/372 will help in finding root cause and get it fixed.

meantime if somebody found a workaround to this can share their solution as well.

@VikramVI I have added the details with logs to https://github.com/facebook/WebDriverAgent/issues/372. Hopefully someone is able to determine a fix.

Currently, my workaround is to not use my custom methods and instead get the entire list of elements in the various locations in a List<> using the “ClassName” attribute and selecting one by index. This is incredibly slow though as some of the lists are very large.

+1 got similar problems after update to 1.6.2 on iOS app.

OS: 10.12.2
Xcode: 8.2.1
Appium: 1.63

I ran into the same issue waiting for a object to appear when loading the Apple maps. I added a wait (sleep), and it seems to work. Possible racine issue?

try {Thread.sleep(4000);}catch (Exception e) {}

It seems to happen when my //xpath is really long.

@Blinkk can you please clarify if you found any workaround for this issue ?

I could find exact steps to reproduce problem

Regards,
Vikram

When I got the error I was checking if a Dialog Message existed, and my work around was to use the message text on the dialog box instead of the long xpath. It’s a pain because the message text changes depending on inputs.

I used this patch for now. It seems to have resolved the issue. This may be included in a future appium release.

@Blinkk Can you please clarify if you still using WDA version which gets installed with latest appium or use the WDA project’s latest version ?

Thanks,
Vikram

I’m using the WDA that comes with Appium 1.6.3 and locally applied the patch mentioned above. It is not committed as part of the WDA project yet so you’ll need to navigate to the pull request and get the code from there, or copy-paste it yourself from the GitHub thread.

-Blinkk