Scrolling up and down using C#

Best practices, code snippets for common functionality, examples, and guidelines.
dugovic.milan
Posts: 68
Joined: Wed Jun 29, 2016 1:19 pm
Location: Frankfurt, Germany
Contact:

Scrolling up and down using C#

Post by dugovic.milan » Fri Jan 27, 2017 2:39 pm

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();
    }
}
Ranorex Explorer @DVAG
Support my Ranorex Ideas & Improvements
My current approach: Ranorex 9.2.0