Forum Xamarin Test Cloud (Read Only)
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

ScrollDownTo how it works?

Hi!
I'm creating my test code for my app (Android). I need to scroll view to tap on input fields which have id and class but the method DragCoordinates() not works really good on my case, because I'm testing on a lot of different devices with different size. I need methods which scroll until a particular element is visible, for example my input field with some id. I found ScrollDown and ScrollDownTo but I didn't understand how they work, for example their arguments?
Can someone give me some example how to use them???
thankyou

Posts

  • JeremyCraigJeremyCraig USMember
    edited February 2018

    Hey there, so here is my android specific usage of it:

          _app.ScrollDownTo(  
                        toQuery: c => c.Marked("ButtonIdentifier"),
                        withinQuery: c => c.Marked("ScrollViewIdentifier"),
                        strategy: ScrollStrategy.Programmatically,
                        timeout: new TimeSpan(0, 0, 60));
    

    so the toQuery is the control of which you want to find and the withinQuery is the layout or scrollable control that is is within.

    Now this only scrolls down to this control so your will still need to tap the button/control.

    Also, incase you are unsure if the control is present on the screen in the first place, I also recommend doing a quick check to see if the button/control you want to find is on the screen to begin with, so here is an example of my implementation of it for tapping buttons

            public void Tap()
            {
                // Hide keyboard so more elements are visible on the screen
                app.DismissKeyboard();
    
                // if the control is on the screen, skip scrolling steps
                if (app.Query(a => a.Marked("ButtonIdentifier")).Length != 1)
                {
                    // If the button is not visible, scroll up
                    app.ScrollToVerticalStart(c => c.Class("LockableScrollView"));
    
                    // Once at the top, search for the element, scrolling down in the process
                    app.ScrollDownTo(
                        toQuery: c => c.Marked("ButtonIdentifier"),
                        withinQuery: c => c.Class("LockableScrollView"),
                        strategy: ScrollStrategy.Programmatically,
                        timeout: new TimeSpan(0, 0, 60));
                }
    
                // Tap the element
                app.Tap(c => c.Marked("ButtonIdentifier"));
    
            }
    
Sign In or Register to comment.