question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

io.appium.uiautomator2 Cached elements 'By.xpath: */child::*' do not exist in DOM anymore when scrolling through a ListView

See original GitHub issue

The problem

When scrolling through a ListView and gathering the child elements the “Cached elements ‘By.xpath: /child::’ do not exist in DOM anymore” exception is thrown.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.18
  • Last Appium version that did not exhibit the issue (if applicable): 1.9.1
  • Desktop OS/version used to run Appium: Windows 10 64bit
  • Node.js version (unless using Appium.app|exe): 12.18.2
  • Npm or Yarn package manager: npm
  • Mobile platform/version under test: Android 8/10
  • Real device or emulator/simulator: Both
  • Appium CLI or Appium.app|exe: CLI

Details

I have an app with a list view that contain 20 elements but only 11 are visible at once. I need all of the child elements so in a loop I gather all the visible ones, then swipe a bit. After that I collect the new child elements and if no new elements appear after a swipe I finish the loop. 100% of the time, when I make the final swipe that does not change the contents of the list view I get the exceptions. (Occasionally I get it in one of the “mid” swipes)

Link to Appium logs

appium_log.txt

Code To Reproduce Issue [ Good To Have ]

            var capabilities = getAndroidOptions(AppPath);
            driver = new AndroidDriver<IWebElement>(AndroidServerUri,
                capabilities);
            driver.ResetApp();
            Size device = driver.Manage().Window.Size;
            var bar = (AppiumWebElement)driver.FindElementById("android:id/tabs");
            ReadOnlyCollection<AppiumWebElement> children = bar.FindElementsByXPath("*/child::*");
            children[9].Click();
            var button = driver.FindElementById("com.tricentis.androidtestapp:id/openListView");
            button.Click();
            Thread.Sleep(300);
            var list = (AppiumWebElement)driver.FindElementById("android:id/select_dialog_listview");
            ReadOnlyCollection<AppiumWebElement> listItems = list.FindElementsByXPath("*/child::*");
            List<string> labels = new List<string>();
            bool breaking;

            while (true) {
                breaking = true;
                Thread.Sleep(500);
                listItems = list.FindElementsByXPath("*/child::*");
                foreach (AppiumWebElement item in listItems) {
                    if (!labels.Contains(item.Text)) {
                        labels.Add(item.Text);
                        breaking = false;
                    }
                }

                if (breaking) {
                    break;
                }

                TouchAction swipe = new TouchAction(driver);
                swipe.Press(device.Width / 2, device.Height / 2).Wait(300)
                    .MoveTo(device.Width / 2, device.Height * 0.3).Release();
                swipe.Perform();               
            }

            driver.CloseApp();




private static AppiumOptions getAndroidOptions(string app)
        {
            var capabilities = new AppiumOptions();
            capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.NoSign, true);
            capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
            capabilities.AddAdditionalCapability(MobileCapabilityType.Udid, "emulator-5554");
            capabilities.AddAdditionalCapability(MobileCapabilityType.AutomationName,
                AutomationName.AndroidUIAutomator2);
            capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.UnicodeKeyboard, true);
            capabilities.AddAdditionalCapability(AndroidMobileCapabilityType.ResetKeyboard, true);
            //capabilities.AddAdditionalCapability(MobileCapabilityType.App, app);
            capabilities.AddAdditionalCapability("dontStopAppOnReset", true);
            capabilities.AddAdditionalCapability("noReset", true);
            capabilities.AddAdditionalCapability("fullReset", false);
            capabilities.AddAdditionalCapability("appActivity", "MainActivity");
            capabilities.AddAdditionalCapability("appPackage", ****);
            return capabilities;
        }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Auto81commented, Jul 23, 2020

looks to be behaving as expected

1reaction
mykola-mokhnachcommented, Jul 23, 2020

@sme81 I think I know what the cause might be. Please check if the fix https://github.com/appium/appium-uiautomator2-server/pull/371 works for you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cached elements do not exist in DOM anymore - Stack Overflow
I had the same issue. I think this happens because every time you click on a photo, the DOM changes. So, when you...
Read more >
The element does not exist in DOM anymore - Appium Discuss
Hi, Appium throws intermittent error selenium.common.exceptions.StaleElementReferenceException: Message: The element 'By.id: ...
Read more >
Appium Crash on StaleElement - Support
StaleElementReferenceException: Cached elements 'By.xpath: //*[contains(@content-desc, 'answerItem')]' do not exist in DOM anymore.
Read more >
Android Native App - Cannot locate listView contents. The ...
Hi. I am using Appium Server (1.3.4) and java_client 2.2.0. I can't locate the contents of the a listview which is under framelayout...
Read more >
is there a way to get the elements "passing", while scrolling ...
The following code scrolls a list view very slowly so that I can get new elements that show when the scroll is over....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found