Page 1 of 1

Read value of combobox

Posted: Wed May 20, 2015 1:38 pm
by jackrabbit
How do I read the current value of a combobox using UserCode?

Code: Select all

string RxPath = "Path to my ComboBox";
Ranorex.Combobox Cbx;
if (! Host.Local.TryFindSingle(RxPath, 2000, out Cbx) ... combobox not found ...
string Value = Cbx.???
I tried using Cbx.Text or Cbx.SelectedItemText but if does not return the current value.

Re: Read value of combobox

Posted: Wed May 20, 2015 1:59 pm
by odklizec
Hi,

Could you please upload a Ranorex snapshot of the combobox in question? Check this page how to create one:
http://www.ranorex.com/support/user-gui ... files.html

Re: Read value of combobox

Posted: Wed May 20, 2015 2:34 pm
by jackrabbit
Here is the snapshot, it is a WPF ComboBox.

I managed to get a current value but I am not sure if it can be trushed. I use the code "Cbx.SelectedItem.Children[0]", however I must remove the "{}" around the value returned to get the actual value. There must be an easier and more reliable way to read the current value of a WPF combobox?

Re: Read value of combobox

Posted: Wed May 20, 2015 2:50 pm
by jackrabbit
Correction, the only way to get the current value is "Cbx.SelectedItem.Children[0].ToString()". But this returns "{text:CURRENT_VALUE}".

Currently, I need to do this to do a match:

Code: Select all

Cbx = find WPF combobox
string Txt = Cbx.SelectedItem.Children[0].ToString();
if (Txt == "{text:" + MyValue + "}") ... Combobox matched MyValue ...

Re: Read value of combobox

Posted: Thu May 21, 2015 9:57 am
by Support Team
Hello jackrabbit,

I’ve seen that you are using Ranorex 5.2.2, please update to our latest version, currently Ranorex 5.3.2. We introduced a new WPF plugin with Ranorex 5.3. This may help you in getting the correct information from your WPF elements.

Regards,
Robert

Re: Read value of combobox

Posted: Tue Jun 26, 2018 8:15 pm
by douglas.velho
Is there how to validate which value was choosen, example if i have the values (Alfa,Beta,Gama) and the test set the value Alfa, is possible validate just this value ?

Re: Read value of combobox

Posted: Thu Jun 28, 2018 7:39 am
by qwertzu
Hi Douglas,
Could you upload a Ranorex Snapshot of the control containing the attribute you would like to validate?
Thanks :-)
regards, qwertzu

Re: Read value of combobox

Posted: Thu Jun 28, 2018 7:33 pm
by douglas.velho
Hi qwertzu

Thanks for answer, i uploaded a Ranorex Snapshot now.
I would like to validate the current value of attribute cdtipoacompanhamentoedit.I Cann't use the TagValue for this validation because this value can be changed.I Would like to validate the label inner text.

Re: Read value of combobox

Posted: Fri Jun 29, 2018 7:52 am
by qwertzu
hey,

it seems like the third option element under this select tag is the one that holds the correct innertext of the element. At least in this current snapshot it looks like that. So you could try to use this path in order to validate the innertext:
/dom[@domain='ranorex.qualitor.software']//select[#'cdtipoacompanhamentoedit']/descendant::option[3]

This path looks for the select tag and takes the 3rd option element under this element.

regards, qwertzu

Re: Read value of combobox

Posted: Fri Jun 29, 2018 8:10 am
by odklizec
Hi,

I think that using hardcoded index of selected option will not work. Definitely not, if his test selects different value. What he needs to do, is to setup two repository elements. First for select box and second for actually selected item.

SelectBox repo item is easy:

Code: Select all

/dom[@domain='ranorex.qualitor.software']//select[#'cdtipoacompanhamentoedit']
To get the text of actually selected item, he needs to use something like this:

Code: Select all

/dom[@domain='ranorex.qualitor.software']//select[#'cdtipoacompanhamentoedit']/option[@tagvalue=$selectedItemValue]
Now he needs to obtain TagValue of selected item, which is actually stored in SelectTag element. For this, he needs to add a GetValue action, pointing to SelectTag (first repo item). The GetValue action should get TagValue and store it in selectedItemValue variable. Then on next line, he can use GetValue or Validate action, pointing to the second repo item, and get its InnerText or validate it. Hope this helps?

Re: Read value of combobox

Posted: Fri Jun 29, 2018 5:38 pm
by douglas.velho
Thanks for help. I'll try this and i'll post the result.

Re: Read value of combobox

Posted: Mon Jul 02, 2018 1:55 pm
by douglas.velho
Thanks for help.
I just can validate using the value of TagValue, but i would not like use Tag to validate this because the value can be changed.

I use a code like this:
variaveltag = repo.QualitorWeb1.Cdtipoacompanhamentoedit.Element.GetAttributeValueText("TagValue");

if (variaveltag == "8")
{
repo.QualitorWeb1.BtnCloseWindow2.Click();
Report.Log(ReportLevel.Success, "Validation", "Success, the value is..."+ variaveltag ,.......
}

else
{
Report.Log(ReportLevel.Failure, "Validation", "Failure, the value is..." + variaveltag ,......

}

At this moment @tagvalue='8' corresponds @innertext=ACOMPANHAMENTO RANOREX 2'

Re: Read value of combobox

Posted: Tue Jul 03, 2018 10:15 am
by odklizec
Hi,

If you use the method I described in my previous post, you don’t have to worry about not matching TagValue of select box and inner text of actual list item, because they will always match. You see, the TagValue in SelectBox points to selected ListItem element. So all you need to do, is to get the actual TagValue from select box and use that value in xpath for ListItem.

Re: Read value of combobox

Posted: Wed Jul 04, 2018 2:05 pm
by douglas.velho
Hi odklizec, thanks for help.

I'll try using code as you described.

Re: Read value of combobox

Posted: Tue Jul 10, 2018 3:56 pm
by douglas.velho
Hi everyone

With help of you and my coworker.This code works to me.
Thanks for help !

IList<OptionTag> optionList = repo.QualitorWeb1.OptionTag2.FindChildren<OptionTag>();
String optionText = "";
foreach(OptionTag opTag in optionList){
if(opTag.Selected){
optionText = opTag.InnerText;
break;
}
}


if(optionText == "ACOMPANHAMENTO RANOREX 2")
{
Report.Log(ReportLevel.Success, "Validation", "Success !!! "+ optionText, repo.QualitorWeb1.OptionTag2Info, new RecordItemIndex(10));
repo.QualitorWeb1.BtnCloseWindow2.Click(); // close Window


}

else
{
Report.Log(ReportLevel.Failure, "Validation", "FAIL !!!! " + optionText, repo.QualitorWeb1.OptionTag2Info, new RecordItemIndex(10));
repo.QualitorWeb1.BtnCloseWindow2.Click(); // close Window
}