Page 1 of 1

Selecting multiple values from a option list

Posted: Thu Sep 13, 2018 3:16 pm
by Noah
Hello,

I'm working in a scenario where i'm suppose to select three option list values from the option list.
I'm using the below code to select but it doesn't seem to be working.

WebDocument webdoc = new WebDocument("/dom[@domain='10.158.118.16:28443']");
SelectTag someSelectTag =webdoc.FindSingle(".//div/fieldset/div//table//tr/td/div//select[@class='v-select-select']");
IList<OptionTag> optTag = someSelectTag.Find<OptionTag>(".//option");
IList<String> p_Name = new List<String>{"ranorex queue 1fi","ranorex queue 2fi","ranorex queue 3fi"};

int c=0;
for(int i=0; i<p_Name.Count;i++)
{
for(int k=0; k<optTag.Count; k++)
{
if(optTag[k].InnerText.Contains(p_Name))
{
Delay.Seconds(1);
optTag[k].Selected=true;
Report.Log(ReportLevel.Success,optTag[k].InnerText + " " + "Queue name has been successfully removed from the update users at Queue list ");
c=1;
}
}

if(c==0){
Report.Log(ReportLevel.Failure,"Unable to remove from update users at Queue list");

}

}

Re: Selecting multiple values from a option list

Posted: Thu Sep 13, 2018 8:05 pm
by odklizec
Hi,

Please upload a Ranorex snapshot of the problematic list. Screenshot is unfortunately not helpful. Thanks.

Re: Selecting multiple values from a option list

Posted: Fri Sep 14, 2018 11:58 am
by Noah
Please find the attached Ranorex snapshot of list.

Re: Selecting multiple values from a option list

Posted: Fri Sep 14, 2018 12:33 pm
by odklizec
Hi,

Thanks, but this is not a Ranorex snapshot. It's just screenshot ;) What I asked for is "snapshot" (rxsnp) file, as described here:
https://www.ranorex.com/help/latest/ran ... hot-files/

Re: Selecting multiple values from a option list

Posted: Fri Sep 14, 2018 1:55 pm
by Noah
My bad haven't used the feature Ranorex snapshot.
please find the attached snapshot file.

Re: Selecting multiple values from a option list

Posted: Fri Sep 14, 2018 7:45 pm
by N612
Hi Noah,

Based on the look of things, you are making this a lot harder and complicated than it needs to be. Is there a reason why you are not using the Ranorex Repository and a simple recording module to select these three options? A recording module is just a visual version of the code that is much easier to manage & maintain. You can always view or convert actions to code if needed.

This example took me roughly 10 seconds to create and does exactly what you need.
Test Page: https://www.w3schools.com/tags/tryit.as ... t_multiple
screenshot.png

Re: Selecting multiple values from a option list

Posted: Mon Sep 17, 2018 8:10 am
by odklizec
Hi,

At first, I have to agree with N612. Many things are much easier (and much more reliably) to do using recording actions and testcase/smartfolder loops, instead of messing with code. For example, using hardcoded xpaths in code is a big NO...NO! This approach creates messy and unmaintainable test solution. If you insists on using code, pass the elements as repository items (or at very least xpaths as string parameters).

At second, what exactly does not work for you? Are there any errors thrown in code? Have you debugged the code? Does your code find the selectbox and its options and fills the lists?

And finally, I would suggest to use standard Click() method or at very least a SetAttributeValue, which sets the required selection attribute. Eventually, use 'Select' method, instead of 'Selected'.

Code: Select all

//use this...
optTag[k].Select();
//instead of this...
optTag[k].Selected=true;
Select not only selects the given element, but it also invokes a 'change' event. Hope this helps?