1

I am currently automating tests for a native app and I have some issues with "ghosts" elements. By "ghosts elements" I mean elements that are in the code and technically on the page but aren't visible to the user.

I am testing using Android and I don't know if the issue would also be present with iOS.

Simply put, I want to click on element X but instead I end up clicking on element Y who isn't visible to the user because X and Y share the same specifications (same text, same element type/class).

I have tried ignoring the element Y by using "isDisplayed()" and "isEnabled()" but it seems like both X and Y are displayed and enabled (even though only X is actually visible to the user).

Is there any way I can discriminate between X and Y using the fact that one is visible to the user and the other isn't? If possible, I don't want to ask the devs to change the code of the app.

If it helps, here is how the app ended up with "ghost elements":

  1. Apps open page 1, page 1 has element Y

  2. Apps open page 2, page 2 is different that page 1 but have element X who is the same as element Y from page 1

  3. We are now on page 2 but page 1 didn't disappear and is just "behind" page 2.

I found this and that who seem to be about the same issue, but there is no solution on how to fix it.


PS: I am using Java but I would accept answers in any language.

10
  • What to you mean under visible? The second element is on the page but out of the current view port? – Alexey R. Aug 21 '20 at 11:58
  • @AlexeyR. I mean "visible for the user". It's like both elements are here but there is something on top of element Y so only element X is visible. – BelovedFool Aug 21 '20 at 12:35
  • Oh I see. That means some other element overlaps one of those two so that it is like behind it? – Alexey R. Aug 21 '20 at 12:43
  • @AlexeyR. Yes (except that "some other element" is more like a full page, but yes). – BelovedFool Aug 21 '20 at 12:49
  • 1
    Okay, I'll form my assumption in the answer and we'll see if it will work – Alexey R. Aug 21 '20 at 13:34
1

I believe the UI has a certain hierarchy and normally object hierarchy has ordered structure (like XML). That means that when you add an element you don't just add it to a random place but to a specific place. Usually it is either the top or the bottom of outer container.

So assume you have the structure like this:

<app>
  <page>
    <element>bottom</element>
  </page>  
  <page>
    <element>top</element>
  </page>  
</app>

If the new page added is being added to the top, then you can access it with /app/page[1]/element

If the new page added is being added to the bottom, then you can access it with /app/page[last()]/element

2
  • FYI, it does seem like each new page is added at the bottom (I'm just hoping that will be a consistent behavior) – BelovedFool Aug 21 '20 at 13:50
  • 1
    Anyway UI framework has to know which page is to render. So the page has to have any property that would help renderer do distinguish it. It is either a position or a attribute of the page. – Alexey R. Aug 21 '20 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.