Xamarin UITest without any reference to ID

We need quick help.
We have button need to refer in Xamarin UITest. Test recorder refers to button with its text app.Tap(x => x.Text("Start Shift\Punchin"));But it fails with error “Unable to find element”.
When Checked in app Source code the Button text was bind to control at run time from resource file(Appresource .resx).
Question 1 - How to refer button in Xamarin UITest with run time binding of text?
Question 2 – How to refer a button without any Automation ID or X:name specified on the code?
Question 3 – How to refer Dropdown button without any ID? Is it possible to access the control value without ID’s?
But it works successfully for GO button because its text is Static assigned to Text property of button.
app.Tap(x => x.Text("Go"));

Can you please check and provide your feedback.

Thanks in advance for your support.

Answers

  • PeterSimonsPeterSimons GBMember ✭✭
    edited October 2017

    There are a few ways of doing it if the button/element is always in the same place you can use index like this:

     app.Tap(a => a.Marked("recordName").Index(0)); 
    

    just by using a query to find the item based on it's place in the tree for example:

     app.Tap(b => b.Marked("TopLevelIdentifier").Class("ChildElementClassName").Marked("ChildElementIdentifier"));
    

    or

     app.Tap(b => b.Marked("TopLevelIdentifier").Class("ChildElementClassName").Index(0));
    

    or if you know what the text is going to be you could use the following query:

     app.Tap(c => c.Property("text").Contains("The string you are looking for"));
    

    If you can post a copy of the Repl(); tree here of just put an app.Print.Tree(); on the line before the failing step and paste the output on here I could give example specific to your app

Sign In or Register to comment.