Page 1 of 1

Reading values from Combo box c#

Posted: Mon Aug 06, 2018 11:25 am
by deatchlock
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

Re: Reading values from Combo box c#

Posted: Thu Aug 09, 2018 5:35 am
by Support Team
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

Re: Reading values from Combo box c#

Posted: Wed Aug 29, 2018 1:58 pm
by deatchlock
Hi Jon,

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

Re: Reading values from Combo box c#

Posted: Tue Sep 04, 2018 9:36 am
by deatchlock
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.

Re: Reading values from Combo box c#

Posted: Tue Sep 04, 2018 12:20 pm
by odklizec
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>()

Re: Reading values from Combo box c#

Posted: Wed Sep 05, 2018 7:13 am
by Support Team
Hi Deatchlock,

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

Regards,

Jon

Re: Reading values from Combo box c#

Posted: Thu Sep 13, 2018 3:29 pm
by deatchlock
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

Re: Reading values from Combo box c#

Posted: Thu Sep 13, 2018 6:23 pm
by odklizec
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.

Re: Reading values from Combo box c#

Posted: Fri Sep 14, 2018 9:20 am
by deatchlock
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 :? .