Host.Local.FindSingle() does not find an element

Class library usage, coding and language questions.
muraszka
Posts: 2
Joined: Mon Dec 11, 2017 7:34 am

Host.Local.FindSingle() does not find an element

Post by muraszka » Mon Dec 11, 2017 2:02 pm

Hello!

I've faced an issue related to Host.Local.FindSingle() method. Sometimes it does not find a required element and I don't know why it happens.
I pass to this method almost absolute rxPath and duration 1m, but time to time get 'No element' exception. Also I tried to capture a snapshot of a form during test execution, the required element is present on the form and it's easly found in Spy by the rxPath passed to the method.

Please describe how FindSingle() actually works and what may be wrong. And maybe you have some suggestion why it happens and some tips how to improve the element searching process and make the test more stable.

If you need additional information feel free to ask. Look forward to your reply.
Thanks.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Host.Local.FindSingle() does not find an element

Post by krstcs » Mon Dec 11, 2017 10:10 pm

Try setting the timeout to 5 minutes. If this solves the issue, then your problem is that the element sometimes takes longer then 1 minute to actually exist. If it doesn't solve the issue, then please post a Ranorex Snapshot of the element in question and the RanoreXPath being used.

Note that the timeout only tells Ranorex how long to search for an element before FAILING the test because the element isn't found. If the element is found more quickly, the test will continue and won't wait for the whole timeout. This is why most of us advise to NOT LOWER timeouts, but sometimes even to raise then significantly in order to make sure that the XPath is finding the element correctly.

The issue could also be that your XPath, even though it is "absolute" is not specific enough. This is why I ask you to post both it and the Snapshot.
Shortcuts usually aren't...

muraszka
Posts: 2
Joined: Mon Dec 11, 2017 7:34 am

Re: Host.Local.FindSingle() does not find an element

Post by muraszka » Tue Dec 12, 2017 11:59 am

Thank you for the fast reply. Yes, it looks like duration issue.
Please answer one more question. May using FindSingle<T> (with generic) speed up time of searching?

Thanks in advance.

Vaughan.Douglas
Posts: 254
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Host.Local.FindSingle() does not find an element

Post by Vaughan.Douglas » Tue Dec 12, 2017 1:16 pm

muraszka wrote: May using FindSingle<T> (with generic) speed up time of searching?
No types are inherited, so specifying the type would be making it more specific. One tip I could add is adding rooted folders, this will have the effect of narrowing the search constraints as objects are found. The downside here is you'll be dealing with the "effective timeout". Another thing, I think Host.local has been deprecated in favor of host.current with the new Selenium integration. I don't know if this would make a difference at this point unless you're executing remotely.
Doug Vaughan