Page 1 of 1

Scrolling up and down using C#

Posted: Fri Jan 27, 2017 2:39 pm
by dugovic.milan
Great solution how to scroll over long list of elements, which are not visible at the moment.

- Public method with parameter of type RepoItemInfo
- Verify if the input argument exists
- Convert RepoItemInfo to Adapter (throwException false, existence of repo item validated in previous step)
- While loop - keep going up/down (page up/down) until the element is visible, then click on the element

To ensure smooth functionality I highly recommend applying EnsureVisible() Invoke Action on the appropriate list of elements.

Code: Select all

public void Scroll(RepoItemInfo repoInfoElement){

	if (repoInfoElement != null){
	Ranorex.Unknown itemAdapter = repoInfoElement.CreateAdapter<Ranorex.Unknown>(false);    				
	do {Keyboard.Press("{Next}");
	} while (itemAdapter.Visible == false);
	itemAdapter.Click();
	}
}
EDIT: More advanced version of scrolling by using "up" and "down" arguments

Code: Select all

public void Scroll(RepoItemInfo repoInfoElement, string Directon){
	if (repoInfoElement != null){
    Ranorex.Unknown itemAdapter = repoInfoElement.CreateAdapter<Ranorex.Unknown>(false);    				
    do {
        switch(Directon)
        	{
        		case "up" : 
        		Keyboard.Press("{PageUp}");
        		break;
        		case "down" : 
        		Keyboard.Press("{Next}");
        		break;
        	}
        		
    } while (itemAdapter.Visible == false);
    itemAdapter.Click();
    }
}