This is a migrated thread and some comments may be shown as answers.

In code behind adress RadMenuItem

1 Answer 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 30 May 2016, 02:04 PM

Hi there,

In the code-behind I like to be able to invoke a click on a menu item and find this menu-item by name or automation-id. By adressing the elements by name you do not have problems when you add menu items.

I can give the RadMenu a name and find it with Find.ByName. However If I give a RadMenuItem a name it does not show up in the DOM tree.

Antoher solution might be to loop trough the RadMenuItems but still I like to be able to adress one of them.

Do you know a solution?

Thanks,

Richard

1 Answer, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 02 Jun 2016, 08:33 AM
Hello Richard,

Thank you for contacting us.

This seems like something in configuration of the RadMenu. If you give a name to the MenuItem, but it is not presented in the DOM tree then it is expected that Test Studio can't find it by name. Maybe you should click first on the menu so the MenuItem is added into the DOM with its name? 

After finding the RadMenu and clicking them you should also refresh the DOM tree or the RadMenu itself.

Here is an example against our demo site:

RadMenu myMenu = ActiveBrowser.Find.ById<RadMenu>("ctl00_ContentPlaceholder1_RadMenu1");

myMenu.Refresh();

RadMenuItem myItem = myMenu.AllItems.Where<RadMenuItem>(_a => _a.Text.Contains("Products")).FirstOrDefault();

myItem.MouseClick();

RadMenuItem myItemTable = myMenu.AllItems.Where<RadMenuItem>(_a => _a.Text.Contains("Tables")).FirstOrDefault();

myItemTable.MouseClick();


Here I find the items by its text.

Hope that helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Richard
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Share this question
or