MenuItem

Class library usage, coding and language questions.
Sampath
Posts: 5
Joined: Thu Aug 17, 2017 10:46 pm

MenuItem

Post by Sampath » Fri Sep 01, 2017 4:07 pm

I figured out Rxpath for the Menuitem and its dropdown. Is their a way to Code loop in c# through each of the dropdown and capture its text and also click on the desired dropdown. It's a wpf application.
Last edited by Sampath on Tue Sep 05, 2017 3:01 pm, edited 1 time in total.

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

Re: MenuItem

Post by odklizec » Tue Sep 05, 2017 7:23 am

Hi,

Of course, it's most probably possible (if the individual menu items could be tracked by Ranorex). Please post a Ranorex snapshot (not screenshot!) of the menu in question.

Basically, you should use code similar to this:
https://www.ranorex.com/help/latest/cod ... oryElement
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

SteveBeck
Posts: 19
Joined: Thu Jul 27, 2017 8:27 am

Re: MenuItem

Post by SteveBeck » Wed Sep 06, 2017 2:29 pm

Here is a method I wrote to do this.

Code: Select all

public static Boolean SelectElementFromComboBox(RepoItemInfo info, string Text)
		{
			try
			{
				Ranorex.Unknown Element = info.FindAdapter<Ranorex.Unknown>();
				
				Element.Click();
				RxPath path = Element.GetPath();
				Ranorex.ComboBox dropdown = Host.Local.FindSingle<Ranorex.ComboBox>(path);

				ListItem lstItem = (from a in dropdown.Items
				                    where a.Text.Equals(Text)
				                    select a).FirstOrDefault();
				
				lstItem.Focus();
				lstItem.Click();
				return true;
				
			}
			catch(Exception e)
			{
				
				return false;
			}
		}

You could also use

Code: Select all

public static Boolean SelectElementFromComboBox(RepoItemInfo info, string Text)
		{
			try
			{
				Ranorex.ComboBox dropdown = info.FindAdapter<Ranorex.ComboBox>();			
						
				ListItem lstItem = (from a in dropdown.Items
				                    where a.Text.Equals(Text)
				                    select a).FirstOrDefault();
				
				
				lstItem.Select();
				return true;
				
			}
			catch(Exception e)
			{
				
				return false;
			}
		}