Forum Xamarin Test Cloud (Read Only)

Not able to query label text with Property("label")

When I query using Marked, It will search through the label (even though it doesn't mention labels on Android in its [documentation] .) I'm trying to use Property("label").Endswith() for a more generic search. But even when using Property to search for an exact string, it returns nothing.
(https://developer.xamarin.com/api/member/Xamarin.UITest.Queries.AppQuery.Marked/p/System.String/ "documentation")

app.Query(c=>c.Marked("02_Voided_NotReviewed"))
Gives this result:
[ [0] {Id => null, Description => "md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsImageView{c54918b V.ED..... ........ 0,0-80,80}", Rect => {Width => 80, Height => 80, X => 0, Y => 718, CenterX => 40, CenterY => 758}, Label => "02_Voided_NotReviewed", Text => null, Class => "md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsImageView", Enabled => true}, ...

while
app.Query(c=>c.Property("label").Contains("02_Voided_NotReviewed"))
returns 0 results

I can use app.Query(c=>c.Property("text").Contains("02")) to accurately query strings in Text. I've tried Property("Label") and Property("label"). Why is "label" behaving different? What am I missing here?

Best Answer

  • DevinGuthrieDevinGuthrie US ✭✭
    Accepted Answer

    @ShantimohanElchuri

    Someone on Stackoverflow figure out what I was doing wrong. It was a misunderstanding of what contentDescription was referring to. Here is a copy of their answer:

    The documentation you linked to says that the Marked method

    Matches common values. For Android: An element with the given value as either id, contentDescription or text.

    It's not immediately apparent, but the Label property that you see in UITest is mapped to the Android element's contentDescription so this should work:

    app.Query(c=>c.Property("contentDescription").Contains("02_Voided_NotReviewed"))
    

Answers

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @DevinGuthrie If I understand correctly, you want to do something like:

    if (label.EndsWith("xyz")) {...}
    

    If so, you can try this:

    string result = app.Query(x => x.Marked("label")).FirstOrDefault().Text;
    if (result.EndsWith("xyz")) {...}
    
  • DevinGuthrieDevinGuthrie USMember ✭✭

    @ShantimohanElchuri

    I understand what you are getting at and it's currently the way i'm working around the issue. But then the work-around involves having to make another query in the if statement to check another string on an object related to the object that has the label. If I could use .Property('label") the matching would occur in the query and I could format the rest of the query to return the other related string I also need to check against. Let me try to clarify. When I query on these properties of an AppResult:
    app.Query(c=>c.Property("text").Contains("xyz")) , app.Query(c=>c.Property("Class").Contains("xyzClass")) or app.Query(c=>c.Property("Id").Contains("xyzId")) I get the expected results according to my query. But when I use
    app.Query(c=>c.Property("label").Contains("xyzLabel")) I am getting zero results even when querying the exact string in the Label property. I'm trying to figure out if i'm doing anything incorrectly or if anyone has any idea what's going on or can report similar issues. Hope that helps.

  • DevinGuthrieDevinGuthrie USMember ✭✭
    Accepted Answer

    @ShantimohanElchuri

    Someone on Stackoverflow figure out what I was doing wrong. It was a misunderstanding of what contentDescription was referring to. Here is a copy of their answer:

    The documentation you linked to says that the Marked method

    Matches common values. For Android: An element with the given value as either id, contentDescription or text.

    It's not immediately apparent, but the Label property that you see in UITest is mapped to the Android element's contentDescription so this should work:

    app.Query(c=>c.Property("contentDescription").Contains("02_Voided_NotReviewed"))
    
Sign In or Register to comment.