Host.Local.FindSingle Slow (Appro 7 seconds to find an item)

Class library usage, coding and language questions.
Posts: 1
Joined: Thu Jun 07, 2018 9:37 am

Host.Local.FindSingle Slow (Appro 7 seconds to find an item)

Post by Gunner » Thu Jun 07, 2018 10:11 am


I am attempting to test a web application, that uses select2 on its dropdown lists.

What it does is replace a standard html <select> element with a prettier version with a search bar, and hides the original select.

I have written the following users code to select and item from one of these boxes:
    public class Select2
        /// <summary>
        /// Select an item from select2 dropdown
        /// </summary>
        public static void SelectItem(string itemToSelect, RepoItemInfo theItem)
        	WebElement web;
        	theItem.Exists(out web);        	

			var dropdown = Host.Local.FindSingle<UlTag>(".//ul[@class='select2-results__options']");
			var options = dropdown.FindDescendants<LiTag>();
			var found = false;	
			foreach(var opt in options){				
				if(opt.InnerText == itemToSelect){
					found = true;
			if(found == false){
				throw new InvalidOperationException("Select 2 option not found");
The above function works but is slow, as the line:
var dropdown = Host.Local.FindSingle<UlTag>(".//ul[@class='select2-results__options']");
Takes 7 seconds to run. I've also noticed it breaks if I have a select 2 box open in a different browser, so it appears this line is trying to find a ui tag across all of the applications open on my host machine, so I can see why this would be inefficient.

Is there a way to get it just to search the page with the WebElement i have a reference to on?

Just a note on the internals of select2, I cannot use Child/Sibling on the web element as the 'select2-results__options' is not near the item in the dom as if there are multiple select2s on a page there will be only one 'select2-results__options' which has it's contents replaced with that of the open list.

Thanks for any help,


User avatar
Ranorex Guru
Ranorex Guru
Posts: 6548
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Host.Local.FindSingle Slow (Appro 7 seconds to find an item)

Post by odklizec » Thu Jun 07, 2018 11:21 am


In my opinion, the only way how to speed up the search is to make the xpath more precise, start search from nearest parent element or, at very least, start search from the DOM element. Try for example something like this:

Code: Select all

WebDocument webDoc = "/dom[@domain='domain_name']";  
var dropdown = webDoc.FindSingle<UlTag>(".//ul[@class='select2-results__options']");  
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration