Count and get name of the context menu item

Ranorex Studio, Spy, Recorder, and Driver.
Bapu16
Posts: 44
Joined: Wed Sep 22, 2021 12:15 pm

Count and get name of the context menu item

Post by Bapu16 » Tue Sep 28, 2021 11:10 am

Hello,

In the file menu there are few items, so may I know how do I count or get the name of the each menu item which then log into the report

I dont want to click on any item but during test I have added file click so all the menu options are visible but after that I am not sure how do I get name of each menu item in one go for e.g. loop
I can select each option one-by-one and then get the value but I am sure there will be some better way to do this, I have tried snapshot, I can see snapshot into repo but when I click on each item then it says element is not visible.

Also non-coding approach would be appreciated
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Count and get name of the context menu item

Post by odklizec » Tue Sep 28, 2021 11:19 am

Hi,

I'm afraid, that what you want is not doable without coding. Also, please learn how to create a snapshot of hidden items:
https://www.ranorex.com/help/latest/ran ... UIelements
Follow the steps from the above link and attach the snapshot to this post. Otherwise, there is not much anyone here can do or suggest. But as mentioned above, you will have to dive into coding.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Bapu16
Posts: 44
Joined: Wed Sep 22, 2021 12:15 pm

Re: Count and get name of the context menu item

Post by Bapu16 » Tue Sep 28, 2021 12:01 pm

Thank you for your response
Please find the attached snapshot file for your reference
You do not have the required permissions to view the files attached to this post.

Bapu16
Posts: 44
Joined: Wed Sep 22, 2021 12:15 pm

Re: Count and get name of the context menu item

Post by Bapu16 » Tue Sep 28, 2021 12:44 pm

OK so I am getting somewhere this is what I have done and I am getting some info but still need to do bit more work
not sure whether this is the best solution but please feel free to suggest while I am still learning
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Count and get name of the context menu item

Post by odklizec » Thu Sep 30, 2021 10:07 am

Hi,

If you just want to get the number of menu items and eventually get their names, there is a very simple way how to achieve both objectives. Luckily for your, all menu items are already created in the UI, just made invisible if they are not activated. But in case you just want to count the items and get their names, it does not really matter ;)

Here is the xpath you can use to identify all menu items (create repo element with such xpath):

Code: Select all

/form[@controlname='MainForm']//menubar[@controlname='mainMenu']//menuitem
And here is the code you can use (pass the above repo element as parameter):

Code: Select all

public void EnumerateRows(RepoItemInfo repoMenuItems)
    {
        string menuItemText = "";
        IList<Ranorex.MenuItem> menuItemsList = repoMenuItems.CreateAdapters<Ranorex.MenuItem>(false);
        //MenuItems count
        int menuItemsCount = menuItemsList.Count;
        //loop the Menu Items lsit and get name of each menu item
        foreach (Ranorex.MenuItem menuItemElement in menuItemsList)
        {
            menuItemText = menuItemElement.Element.GetAttributeValueText("Text"); //reads content of each MenuItem
        }
    }
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration