If I try to access / act on a repo item or create a new element variable from path for one of the checkboxes not on screen when the page loads, it fails (ElementNotFoundException).
I can work around this by trying to re-create the element repeatedly while scrolling down a 'page' at a time.
public static bool GetCheckBoxElement(string HoldType, out CheckBox elem) { string CheckBoxPath = repo.OrderEntry.Holds.GENERICHoldCheckBoxInfo.Path.ToString().Replace("HOLDTYPE", HoldType); ScrollBar sb = repo.OrderEntry.Holds.HoldsScrollBar; while(sb.Value != 0){sb.Click(Location.UpperCenter);} elem = null; while (elem == null & sb.Value < sb.MaxValue) { try { elem = CheckBox.FromPath(CheckBoxPath); } catch(ElementNotFoundException) { elem = null; sb.Click(Location.LowerCenter); } } if (elem == null){return false;} else{return true;} }
(The GENERICHoldCheckBox repo item lets me find checkboxes based on their following Hold Code - see screenshot).
However...If I scroll past the element at least once (which, as I say, I must do in order to access / act on / create a new variable from path of it in the first place), it seems that 'Visible' is set to 'True', and so it stays - even if it has since scrolled back out of view.
So, if there is any possibility that the checkbox may have scrolled off screen since it was assigned to a variable, I have to re-do that process (assigning it, including scrolling around until it's on screen if that fails) to make sure it's still visible, because if I try to just scroll until it's visible, it doesn't scroll - like I say, 'Visible' remains true, even though it's not actually on screen. If I try to tell it to click or check the checkbox, it will act on whatever checkbox is nearest to the location the element was at when it was assigned to a variable.
I can work around this just by re-doing the whole process of assigning it to a variable and scrolling if that fails (call the above code again), and then immediately (before it may scroll away again) checking or changing the state, but it would be nice for this and other similar sorts of cases I've run into if there were just a simple way to force ranorex to refresh a repo item to reset properties like existence, visibility, the location on screen, etc. It doesn't always seem to do this on its own when parts of the UI change, and it can be very frustrating when it claims something is visible when it's clearly not, or can't find a repo item because it wasn't visible when the screen first loaded, but is now.
Is there some built-in way of doing that (getting Ranorex to completely refresh / retry) that I just haven't noticed before? If not, have any of you found a nicer way of working around it? The code above does get the job done, but I kinda think it smells. Any help would be appreciated; I've run into similar issues to this a fair few times, now.