Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding an element with an XPath locator is very slow #132

Open
PiotrNestor opened this issue Jan 16, 2025 · 3 comments
Open

Finding an element with an XPath locator is very slow #132

PiotrNestor opened this issue Jan 16, 2025 · 3 comments

Comments

@PiotrNestor
Copy link

PiotrNestor commented Jan 16, 2025

@aristotelos

FlaUI.WebDriver Version: v0.3.1

We have a complex legacy Desktop application that exposes FrameworkType Win32 automation interface.

An example XPath like: //Tab[@name='customers']//Text[contains(@name,'Drag and drop field here')]
can take up to 45 seconds to locate the related element.
Note that even a full Xpath for the above element example takes 10 seconds to locate the element.

What can be done to speed up this mechanism?
Any suggestions for a locator strategy that could improve the situation?

@PiotrNestor
Copy link
Author

PiotrNestor commented Jan 17, 2025

Some additional findings when using FLaUInspect (UIA3 mode) with the above app:

  • it's possible to find, build and expand the above element properties in the elements structure within 1-2 seconds
  • selecting the element in question in the FlaUInspect element structure, highlights the element in the application within 1-2 seconds. Also, the element's bounding rectangle is recalculated instantly when moving and resizing the application.

So, obviously it's possible to manipulate the app elements very quickly via the exposed automation. But using XPath locators is very slow ...

@aristotelos
Copy link
Collaborator

It may be that not the X-Path is slow, but the resolving of the top level window to which the X-Path is resolved relatively. I myself have experienced that the GetAllTopLevelWindows() is very slow in FlaUI / Windows automation itself. See also FlaUI/FlaUI#616, FlaUI/FlaUI#596. Could that be the case?

If it is the X-Path, it may be sped up by avoiding the use of // (recursive search) and using / (children search) instead. In general, I would recommend the use of automation IDs and not X-Path.

@PiotrNestor
Copy link
Author

@aristotelos
This is unclear or confusing :(

I was under the impression that all XPath like '//...' are relative to the present driver window ...

In our implementation, the code is performing driver.SwitchTo().Window(handle)
Example

...
    var handles = driver.WindowHandles;
    foreach (var handle in handles)
    {
        driver.SwitchTo().Window(handle);

        // Check if an UI element for the window is visible
        // if so ... return
    }

Obviously we try to use 'AutomationId' is available. Unfortunately these are not available in many cases.
XPath with single, initial '//' are mostly very fast
Only more complex XPath with multiple '//' might be very slow where the application's window element structure is deep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants