Page 1 of 1

Scroll until you spot the desired element

Posted: Sat Jul 13, 2019 5:58 am
by Subhadip
Hi,

Here is a scenario I am trying to automate.
I have an element e in my ios app.
And that is dynamically placed in the screen.
Sometime we get the element on the top of the screen, but sometime it goes down.

So,I will have to scroll and check if the element is there or not, if its there I have to click on it.
How do I achieve this.

Thank you,
Subhadip

Re: Scroll until you spot the desired element

Posted: Mon Jul 15, 2019 8:38 am
by odklizec
Hi,

I'm doing something like this in one of my Android tests, where some elements are loaded in memory only if they are scrolled to the visible area of screen. Here is a sample code:

Code: Select all

public static void ScrollListToElement(RepoItemInfo viewScrollElement, RepoItemInfo sequenceElement)
{
    if (!sequenceElement.Exists(10000))
    {
        do 
        {
            viewScrollElement.CreateAdapter<Ranorex.Unknown>(false).Swipe(Location.Center, ValueConverter.ArgumentFromString<Ranorex.Core.Recorder.Touch.GestureDirection>("SwipeDirection", "Up (270°)"), ValueConverter.ArgumentFromString<Ranorex.Core.Distance>("Distance", "200"), ValueConverter.ArgumentFromString<Ranorex.Duration>("SwipeDuration", "500ms"), 0);
            Delay.Milliseconds(500);
        } while (!sequenceElement.Exists(10000));
    }
}
Hope this helps?

Re: Scroll until you spot the desired element

Posted: Tue Jul 16, 2019 12:06 pm
by Subhadip
Hi,

Thank you so much for your reply.
I am new to user code . So, having difficulty in understanding how to declare a repo element in my code and what are Adopters and how to use them.
Could you please help me on that.

Thank you,
Subhadip

Re: Scroll until you spot the desired element

Posted: Tue Jul 16, 2019 1:19 pm
by odklizec
Hi,

Check my previous post. I just updated the sample code, with method declaration. Basically, you must add this method to recording of your choice (as a code action) and link repository elements for scrolable view item and element you want to find. Code should do the rest of voodoo magic ;)

Re: Scroll until you spot the desired element

Posted: Wed Jul 17, 2019 7:25 am
by Subhadip
Hi,

Thank you for your response.
I tried putting in the script and associating two elements with it to use that as a Code action.
But, its not working, because if (!sequenceElement.Exists(10000)) condition is returning false even when the element is not visible in the screen.

Can you help me out on this.

Thank you,
Subhadip

Re: Scroll until you spot the desired element

Posted: Wed Jul 17, 2019 7:28 am
by odklizec
Hi,

I'm afraid, without seeing, at very least, a Ranorex snapshot (NOT screenshot) of your application and repo xpath, you are using for given element, there is not much anyone here can do or suggest. Could you please share the snapshot and xpath?

Re: Scroll until you spot the desired element

Posted: Fri Apr 24, 2020 2:08 pm
by ganesh21392
the below code works

[UserCodeMethod]
public static void ScrollToElement(RepoItemInfo ScrollElement, RepoItemInfo ElementToFind)
{
if (!ElementToFind.Exists(500))
{
do
{

ScrollElement.CreateAdapter<Ranorex.Unknown>(false).Swipe(Location.Center, ValueConverter.ArgumentFromString<Ranorex.Core.Recorder.Touch.GestureDirection>("SwipeDirection", "Up (270°)"), ValueConverter.ArgumentFromString<Ranorex.Core.Distance>("Distance", "200"), ValueConverter.ArgumentFromString<Ranorex.Duration>("SwipeDuration", "500ms"), 0);
Delay.Milliseconds(500);
} while (!ElementToFind.Exists(500));
}
}