Unable to find UI element, except when starting Spy before

Class library usage, coding and language questions.
hbrd
Posts: 2
Joined: Tue Jun 23, 2020 11:28 am

Unable to find UI element, except when starting Spy before

Post by hbrd » Tue Jun 23, 2020 3:36 pm

Hello,

we are having trouble with a Problem after updating from Ranorex 7 to the most recent version (9.3.2).
We are unable to find elements of a Dynamic WebDocument, more specifically a compiled HTML help document (.chm).
Attached you find the Snapshot of the help page, we need to check the existence of the selected caption.

I have created a minimal C# program, based on the Ranorex API documentation, that perfectly replicates the behaviour:

Code: Select all

using Ranorex;
using Ranorex.Core;
using System;
using System.Runtime.CompilerServices;

namespace RanorexTest
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            InitResolver();
            RanorexInit();
            run();
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void InitResolver()
        {
            Ranorex.Core.Resolver.AssemblyLoader.Initialize();
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void RanorexInit()
        {
            TestingBootstrapper.SetupCore();
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        private static int run()
        {
            Element element;
            if (!Host.Local.TryFindSingle("/dom[@page='meta.htm']//div[#'body']//div[@innertext~'^Dokumententyp']//b[@innertext~'^Title']", out element))
                throw new ElementNotFoundException();

            return 0;
        }
    }
}
When the help page is opened BEFORE the initializaitons, everything works fine. But we init ranorex first, and then one small part of our tests is opening and checking the help page. In this case, none of the elements in the help window can be found with ranorex.
However, when we run Ranorex Spy after opening the help page and before trying to find the element, everything works fine again.

We can replicate the problem on different machines, all running Windows 10 1909 64 Bit.

I assume the solution is quite simple, I hope you can help me.
Attachments
Program.cs
Minimal csharp program
(1.04 KiB) Downloaded 8 times
Snapshot_b_FAS.rxsnp
Snapshot of the caption we need to check
(62.33 KiB) Downloaded 1 time
Last edited by hbrd on Wed Jun 24, 2020 3:09 pm, edited 1 time in total.

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

Re: Unable to find UI element, except when starting Spy before

Post by odklizec » Wed Jun 24, 2020 7:14 am

Hi,

Have you tried to replicate the problem with standard Ranorex test suite and recordings, using repository elements? Also, could you please post exact error message you are getting (ideally, entire report). Also, try to add browser to Ranorex whitelist.

I see nothing wrong with the xpath or snapshot you posted, so I assume it must be something else machine/code related. It would be interesting to see if the same works with Ranorex recording modules and test suite.
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

hbrd
Posts: 2
Joined: Tue Jun 23, 2020 11:28 am

Re: Unable to find UI element, except when starting Spy before

Post by hbrd » Wed Jun 24, 2020 3:03 pm

Hello,

I have tried your suggestions, and Ranorex Studio seemed to have no trouble finding the elements.

I played around a bit, and finally found the problem. I discovered that the little testing program I posted here suddenly worked.
The problem was, that our call to TryGetElement was not made by a STAThread. Wrapping the call in a STAThread fixed the problem for us.