GhostyIs1337
GhostyIs1337

Reputation: 33

TestStack.White can't click on menu bar item?

I'm currently making a program that will automate a task that I need to do on a program.

One issue I'm currently having, is "clicking" on a menu in a menu bar.

I found the class name for the menu bar using Spy++, it's called TActionMainMenuBar, but everything "under" it is localized as ammbSSC.

https://i.sstatic.net/swlxU.png

I can find the main menu bar using:

var x = window.Get(SearchCriteria.ByClassName("TActionMainMenuBar"));

Console.WriteLine(x.ToString());

Which returns:

Panel. AutomationId:1311676, Name:ammbSSC, ControlType:pane, FrameworkId:Win32
TestStack.White.Application

But trying to find "ACTIONS" using .ByText or .ByIndex (or anything else really) throws an exception that it can't find "ACTIONS".

Can I even find the text like this? Or should I resort to using mouse input - i.e. automating mouse movements?

EDIT:

I've tried doing it like this as well:

window.GetMultiple(SearchCriteria.ByControlType(ControlType.Pane).AndByClassName("TActionMainMenuBar"))[1].Click();

But that throws a 'Index was outside the bounds of the array.'

I've also tried doing it as:

window.GetMultiple(SearchCriteria.ByControlType(ControlType.Pane))[1].Click();

And:

window.GetMultiple(SearchCriteria.ByControlType(ControlType.Pane).AndByClassName("TActionMainMenuBar").AndByText("ACTIONS"));

window.Click();

But that moves my mouse to around the center of my screen.

Upvotes: 1

Views: 696

Answers (1)

RuthlessKnight
RuthlessKnight

Reputation: 39

I've seen "menu bar" being wrapped in another control, which you can then use to find what you presumed to be the child element of said menu bar.

In one of my cases, the menu bar was in a window (popup), I then find the "action" in the popup as below.

Window PopUp => Window.ModalWindows().Last(); //Gets the latest popup
var all = PopUp.GetMultiple(SearchCriteria.ByControlType(ControlType.Text)); //Get all the options, most cases, the menu items are in a textbox, use whatever you see in your spy tool
var menu = all.FirstOrDefault(m => m.Name.Equals("actionValue") && m.Visible); 
menu?.Click();

Heads up - I've ran into click issue with this type of control before, hopefully that doesn't happen for you..."thread click" on the object to get it to work.

Upvotes: 1

Related Questions