Search code examples
xamarinxamarin.iosxamarin.androidxamarin-test-cloudxamarin.uitest

Read value from Text Field in Xamarin UI test REPL


I am working on automation of our cross-platform app in Visual Studio 2013 with Xamarin. And I am currently struggling to read the value from Text Field on a page. Is there a method that can be used to do this?

Example of the element attributes from REPL:

Id => "app_url",
Label => "ApplicationUrlEntryField",
Text => "https://myurladdress.com",
Class => "android.widget.AutoCompleteTextView",
Enabled => true

Now, i need the Text value => https://myurladdress.com

Thanks.

[EDIT]

Actually solve it:

app.Query(x => x.Marked("ApplicationUrlEntryField").Invoke("getText")); - get the Value of a text by its id


Solution

  • You can use the Text Property from app.Query to retrieve the value.

    I also like to include a null-check and return string.Empty if for some reason app.Query fails.

    string GetApplicationUrlEntryFieldText()
    {
        System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery> applicationUrlEntryField = x => x.Marked("ApplicationUrlEntryField");
    
        app.WaitForElement(applicationUrlEntryField);
    
        var applicationUrlEntryFieldQuery = app.Query(applicationUrlEntryField);
    
        return applicationUrlEntryFieldQuery?.FirstOrDefault()?.Text ?? string.Empty;
    }