Question

Tried every listed option but cannot find Ribbon within a Pane control using White. Although VisualUIAVerify shows it in a tree.

"window" "Test 0.0.1" "MainForm"
  |--"pane" "Dock Top" "_MainForm_Toolbars_Dock_Area_Top"
    |--"" "Ribbon" ""
      |--"tab" "Ribbon Tabs" ""
        |--"tab item" "Tools" ""

I want to automate click on tab item "Tools". but can find only a "pane"

import clr
import sys
sys.path.append(r"C:\TEMP\white")
clr.AddReference("White.Core")
clr.AddReference("White.NUnit")
from White.NUnit import *
from White import *
from White.Core import *
from White.Core.Configuration import *
from White.Core.UIItems import *
from White.Core.UIItems.WindowItems import *
from White.Core.UIItems.ListBoxItems import *
from White.Core.UIItems.Container import *
from White.Core.UIItems.Finders import *
from White.Core.Factory import *
from White.Core.Finder import *
from White.Core.AutomationElementSearch import *
from White.Core.WindowsAPI import *

from System.Diagnostics import Process
wp= Process();
wp.StartInfo.FileName = r"c:\TEMP\gui\TestShell.exe";
wp.StartInfo.Arguments = r"TestShell.taco -e DBA -s qa";        
wp.Start();
wapp = Application.Attach( wp );
wnds=Application.GetWindows(wapp)
wnd=wnds[0]

#test
>wnd.Name
"Test 0.0.1"

I can even click tab Tools provided coordinates (IronPython).

def click(cp,mouse,x,y):
    cp = wnd.Bounds.TopLeft;
    cp.Offset(x, y);
    mouse = Desktop.Instance.Mouse;
    mouse.Location = cp;
    mouse.Click(cp);

cp = wnd.Bounds.TopLeft;
mouse = Desktop.Instance.Mouse;
mouse.Location = cp;
mouse.Click(cp);
click(cp,mouse,120,50) #tools

Getting to a pane:

pn=wnd.GetElement(SearchCriteria.ByAutomationId("_MainForm_Toolbars_Dock_Area_Top"));

tying to find a ribbon

rbn=pn.GetElement(SearchCriteria.ByAutomationId("Ribbon"));

or find all children

pn.FindAll(TreeScope.Children,  Condition.TrueCondition)

Nothing seems to work.

Was it helpful?

Solution

The inconsistencies you're seeing are likely the result of the fact that UIA Verify is using the native COM version of the UIA library and white still uses the old managed library.

In my experience, the native library tends to be faster, more stable, and more compatible than the older managed library, so you should consider transitioning your code over to using it (or if you're feeling generous, contributing code to white on GitHub to update it).

It's been a while since I've done that migration myself, so I can't recall the specifics, but basically you'll need to produce an interop DLL that will allow your .NET application to call the native UIA methods. Then you can optionally create your own wrapper library or possibly use one of those mentioned below.

I'd recommend referring to these for help in making the transition:

UI Automation COM-to-.NET Adapter - An early attempt at creating a wrapper for the COM API. I had trouble just straight up using this, but it was helpful to take a look at initially. Also search for some of the MSDN support forum posts about the COM API made by this wrapper's developer. I unfortunately can't link to them because of my low StackOverflow rep (long time lurker, first time answerer).

UIA Verify Source Code - You can see that they have in their source code a UIAComWrapper which is used to access the COM interface. You can also take a look in that project at how they're producing the interop DLL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top