Read value of combobox

Ask general questions here.
jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Read value of combobox

Post by jackrabbit » Wed May 20, 2015 1:38 pm

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.

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

Re: Read value of combobox

Post by odklizec » Wed May 20, 2015 1:59 pm

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
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

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Read value of combobox

Post by jackrabbit » Wed May 20, 2015 2:34 pm

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?
Attachments
cbx.rxsnp
(17.46 KiB) Downloaded 56 times

jackrabbit
Posts: 47
Joined: Wed Mar 18, 2015 10:06 pm

Re: Read value of combobox

Post by jackrabbit » Wed May 20, 2015 2:50 pm

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 ...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Read value of combobox

Post by Support Team » Thu May 21, 2015 9:57 am

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
.
Image

douglas.velho
Posts: 7
Joined: Wed Dec 06, 2017 8:33 pm

Re: Read value of combobox

Post by douglas.velho » Tue Jun 26, 2018 8:15 pm

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 ?

qwertzu
Posts: 178
Joined: Wed Jan 25, 2017 11:08 am

Re: Read value of combobox

Post by qwertzu » Thu Jun 28, 2018 7:39 am

Hi Douglas,
Could you upload a Ranorex Snapshot of the control containing the attribute you would like to validate?
Thanks :-)
regards, qwertzu

douglas.velho
Posts: 7
Joined: Wed Dec 06, 2017 8:33 pm

Re: Read value of combobox

Post by douglas.velho » Thu Jun 28, 2018 7:33 pm

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.
Attachments
VALIDATE_VALUE_RANOREX_2.rxsnp
(348.03 KiB) Downloaded 9 times

qwertzu
Posts: 178
Joined: Wed Jan 25, 2017 11:08 am

Re: Read value of combobox

Post by qwertzu » Fri Jun 29, 2018 7:52 am

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

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

Re: Read value of combobox

Post by odklizec » Fri Jun 29, 2018 8:10 am

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?
Last edited by odklizec on Fri Jun 29, 2018 8:20 pm, edited 1 time in total.
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

douglas.velho
Posts: 7
Joined: Wed Dec 06, 2017 8:33 pm

Re: Read value of combobox

Post by douglas.velho » Fri Jun 29, 2018 5:38 pm

Thanks for help. I'll try this and i'll post the result.

douglas.velho
Posts: 7
Joined: Wed Dec 06, 2017 8:33 pm

Re: Read value of combobox

Post by douglas.velho » Mon Jul 02, 2018 1:55 pm

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'

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

Re: Read value of combobox

Post by odklizec » Tue Jul 03, 2018 10:15 am

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.
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

douglas.velho
Posts: 7
Joined: Wed Dec 06, 2017 8:33 pm

Re: Read value of combobox

Post by douglas.velho » Wed Jul 04, 2018 2:05 pm

Hi odklizec, thanks for help.

I'll try using code as you described.

douglas.velho
Posts: 7
Joined: Wed Dec 06, 2017 8:33 pm

Re: Read value of combobox

Post by douglas.velho » Tue Jul 10, 2018 3:56 pm

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
}