Reading values from Combo box c#

Ask general questions here.
deatchlock
Posts: 34
Joined: Mon Mar 19, 2018 10:02 am

Reading values from Combo box c#

Post by deatchlock » Mon Aug 06, 2018 11:25 am

Hi,

I am trying to get the values from the Combo box manually meaning specifying everything through the code. The code that I have at the moment reads only the first value in the combo box and I need all the values that exist within Combo box. Any help is appreciated :)


//combo box values
IList<ComboBox> comboBox = Host.Local.Find<ComboBox>(xpathCombo);

        	int lengthCombo = comboBox.Count;
        	for(int i=0; i<lengthCombo; i++) 
        	{
        		ComboBox combo = comboBox;       		
        		string comboType = combo.Element.GetAttributeValueText("FullType").ToString();
        		if( comboType.Equals("Ranorex.Plugin.Wpf.DepoGroup<System.Windows.Controls.ComboBox>") &&        		   
        		    !buttonClicked)
        			{
        			combo.Click(); 			        			
				Ranorex.Report.Info(combo.ToString());
        			Ranorex.Report.Screenshot(combo);
        			GetAndStoreTextPictureAndOCRFromElement(combo, path);
	        		XMLFileConverter.GetXMLFromObject(xmlstorage,currentResultFolder+@"RanorexResult_.xml");    		
        			}        		
        		}
        	 }


Edit by Support Team: Use code tag for better readability

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Reading values from Combo box c#

Post by Support Team » Thu Aug 09, 2018 5:35 am

Hi deatchlock,

Thank you for reaching out to us in regards to your combo box question.

In a scenario like this, I will usually try to let the RanoreXPath do all the heavy lifting. What I mean by this is that I will try to craft my RxPath so that it returns all objects that I am interested in. In the example below, there is a single select tag which has 4 options:

https://www.w3schools.com/tags/tryit.as ... tml_select

The first thing I do is create an RxPath to return all options:
  • 1.png

Code: Select all

RanoreXPath:  /dom[@caption='Tryit Editor v3.5']/body/div[7]//iframe[@name='iframeResult']/?/?/select/option
Next, we can use create adapters to create an individual adapter for each option within the combobox. After this we can iterate over each item:
 public void getVals()
        {
            IList<Ranorex.OptionTag> someSelectTag = repo.TryitEditorV35.SomeSelectTagInfo.CreateAdapters<Ranorex.OptionTag>();
            
            foreach(Ranorex.OptionTag option in someSelectTag)
                Report.Info("Options: " + option.InnerText);
        }
And my output:

Code: Select all

 Options: Volvo  
 Options: Saab  
 Options: Opel  
 Options: Audi  
If this will not work for your scenario or isn't quite what you were looking for, please let me know as I would be happy to make another suggestion.

I hope this helps!

Regards,

Jon
You do not have the required permissions to view the files attached to this post.

deatchlock
Posts: 34
Joined: Mon Mar 19, 2018 10:02 am

Re: Reading values from Combo box c#

Post by deatchlock » Wed Aug 29, 2018 1:58 pm

Hi Jon,

thank you for the help. It did help me to solve the issue. Sorry for the late reply :wink:

deatchlock
Posts: 34
Joined: Mon Mar 19, 2018 10:02 am

Re: Reading values from Combo box c#

Post by deatchlock » Tue Sep 04, 2018 9:36 am

Hi John,

I thought at the beggining that it works but it doesnt. My situation is a bit more complicated then that ( at least from my perspective). Please check the snapshot for more info. In my case seems that ContextMenu is tottally separated from the application therefore I don´t know how to access it and get values from the list.

IList<ContextMenu> contextMenu = Host.Local.Find<ContextMenu>("/contextmenu"); => this always returns 0 elemtns.
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: Reading values from Combo box c#

Post by odklizec » Tue Sep 04, 2018 12:20 pm

Hi,

You need to use xpath(repo item) like this:
/contextmenu[@class~'HwndWrapper']/listitem
And this code should return the list of ListItems...
IList<Ranorex.ListItem> contextMenuItems = repo.NameOfRepoElementInfo.CreateAdapters<Ranorex.ListItem>()
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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Reading values from Combo box c#

Post by Support Team » Wed Sep 05, 2018 7:13 am

Hi Deatchlock,

Have you made any progress with the help of odklizec's example? If not, where are you getting stuck?

Regards,

Jon

deatchlock
Posts: 34
Joined: Mon Mar 19, 2018 10:02 am

Re: Reading values from Combo box c#

Post by deatchlock » Thu Sep 13, 2018 3:29 pm

Hi guys,

apologies for a late reply I was occupied with different part of the project. No unfortunately it dosen´t work. Here is my path:
string xpathCont = @"/form[(@title='KePlus MAX' or @title='DemoDialog' or @title='ManualLogbookEntry') and @win32OwnerWindowLevel=" + TopWin32OwnerWindowLevel + "]/contextmenu[@class='HwndWrapper' and @enabled='True']/listitem";

ignore this "TopWin32." thing, this is from my internal process. The value of xpathCont is empty.

this is where i define the list with the given xpath : IList<ContextMenu> context = Host.Local.Find<ContextMenu>(xpathCont);

Let me show you how does it look when the contextmenu is not opened. As you will see the context menu is not reachable from there , I have to first open drop down and then with RanorexSpy get the contextmenu by clicking on the border of the contextmenu.

Maybe I have misunderstood the solution from you Odklizec.

Regards

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

Re: Reading values from Combo box c#

Post by odklizec » Thu Sep 13, 2018 6:23 pm

Hi,

At first, the ilist you are trying to create must be declared with <ListItem> Instead of <ContextMenu>. Your ilist tries to find ContextMenu, but the xpath points to listitems!

At second, is there a reason why you don’t use repository, as shown in my example? Using “find” method only complicates the things.
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

deatchlock
Posts: 34
Joined: Mon Mar 19, 2018 10:02 am

Re: Reading values from Combo box c#

Post by deatchlock » Fri Sep 14, 2018 9:20 am

Hi,

you are right I am pointing to the wrong item, that is taken care off. The reason is that I am working with a complicated application and I am working in Visual Studio. The algorithm looks through the opened applications and searches for one with the given name in my case "Keba.Max.App". After the application is found, it is brought the front screen and the process of traversing GUI elements is started. Therefore I have to use Host.Local.Find for all other similar actions like this one. For example buttons and text elements are working without problem only this one contextmenu with listitems in it is giving me headache :? .