In code behind adress RadMenuItem

2 posts, 0 answers
  1. Richard
    Richard avatar
    8 posts
    Member since:
    Mar 2015

    Posted 30 May Link to this post

    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

  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 01 Jun Link to this post

    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!
Back to Top