microsoft / WinAppDriver

Windows Application Driver
MIT License
3.57k stars 1.39k forks source link

Clicking on a Tab Drawn by a Telerik DocumentWindow #1634

Open JCTrans opened 2 years ago

JCTrans commented 2 years ago

Bear with me cause it's my first time using WinAppDriver, and this is a bit of a doozy.

I'm trying to implement UI testing via WinAppDriver on an old WPF application primarily built in C# using Telerik controls. It had basically no accessibility elements set and I've been more or less doing them alongside me building the UI tests themselves. The latest hurdle is that the majority of the functionality is located within a window located relatively deep under 3 other panes of the application.

image Sorry to block some of it off, I'm unsure if I can show some of the particulars here I'm being safe instead of sorry

Now I've gone through and added accessibility names to everything, but my understanding is that the home tab shown in the upper left of that picture is drawn by the Telerik DocumentWindow in the designer.cs for that form:

        this.home.AccessibleName = "dwHome";
        this.home.AccessibleRole = System.Windows.Forms.AccessibleRole.Window;
        this.home.CloseAction = Telerik.WinControls.UI.Docking.DockWindowCloseAction.Hide;
        this.home.Controls.Add(this.gridPane);
        this.home.DocumentButtons = Telerik.WinControls.UI.Docking.DocumentStripButtons.None;
        this.home.Location = new System.Drawing.Point(6, 29);
        this.home.Name = "dwHome";
        this.home.PreviousDockState = Telerik.WinControls.UI.Docking.DockState.TabbedDocument;
        this.home.Size = new System.Drawing.Size(886, 400);
        this.home.Text = "Home";
        this.home.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.None;

And I've attempted everything I can think of for accessing home from my WinAppDriver testing suite. After setting the accesibility ID I can reach documentTapStrip1 no problem with var home = session.FindElementByAccessibilityId("documentTabStrip1"); but doing home.FindElementByAccessibilityId("dwHome").Click(); consistently throws not found errors. I'm sure even if it did find it it would simply click near the center of the window instead of on the actual button itself.

Does anyone know how I would be able to programmatically click on that Home tab? I'm willing to resort to coordinate based clicking as an absolute last resort at this point because I don't anticipate Home to move in this application, but it's a gross way of doing it.

anunay1 commented 2 years ago

try home.FindElementsbyxpath("/") this will give you all the child elements of home, that will make sure that winappdriver is able to find "dwHome"

JCTrans commented 2 years ago

@anunay1 I've actually tried that, trying to put it into a children variable and get the count: var children = home.FindElementsByXPath("/"); Console.WriteLine(children.Count.ToString()); I had an issue with it timing out but that's because this particular page of the application has literally thousands of child elements and couldn't search fast enough. I went to another window with a minimal amount of child elements. When I did so I was finding only a single element every time until I hit a bottom pane. All of these were formerly unnamed with accessibility names so I went into the design of that form and included them, and the accessibility tree now looks like this: image Now, for the record, the tabs on this page look like this: image And by all means these don't appear anywhere in the tree even as unnamed children. They simply aren't included, at least in accessibility insights and Inspect.exe, as elements.

What I'm supposing is happening here is that these tabs are drawn by documentTabStrip1 and therefore aren't actual Component components. It's possible these are somehow actually in there but hidden behind the Telerik control. It's possible this may be an issue outside of WinAppDriver, but I'm assuming that functionality to click on drawn objects is something that already exists in some capacity?

liljohnak commented 2 years ago

I went to another window with a minimal amount of child elements. When I did so I was finding only a single element every time

Its weird, but to get child elements when searching from an element, you need to use elm.FindElementsByXPath("*/*")

JCTrans commented 2 years ago

I went to another window with a minimal amount of child elements. When I did so I was finding only a single element every time

Its weird, but to get child elements when searching from an element, you need to use elm.FindElementsByXPath("*/*")

Ah, crap. I didn't update it in the post above while I was writing it. You're super right and that's what I ended up doing to find the children that existed. Doing elm.FindElementsByXPath("/") did nothing at all.

liljohnak commented 2 years ago

Yeah, I am also testing on msedgedriver. It expects elm.FindElementsByXPath("*") to find children