Selecting multiple values from a option list

Ask general questions here.
Noah
Posts: 5
Joined: Tue Aug 21, 2018 1:31 pm

Selecting multiple values from a option list

Post by Noah » Thu Sep 13, 2018 3:16 pm

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");

}

}
Attachments
Combo box 9-13-2018 7-14-48 PM.jpg
Selecting multiple items
Combo box 9-13-2018 7-14-48 PM.jpg (36.78 KiB) Viewed 155 times

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

Re: Selecting multiple values from a option list

Post by odklizec » Thu Sep 13, 2018 8:05 pm

Hi,

Please upload a Ranorex snapshot of the problematic list. Screenshot is unfortunately not helpful. Thanks.
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

Noah
Posts: 5
Joined: Tue Aug 21, 2018 1:31 pm

Re: Selecting multiple values from a option list

Post by Noah » Fri Sep 14, 2018 11:58 am

Please find the attached Ranorex snapshot of list.
Attachments
Capture.PNG
List snapshot
Capture.PNG (48.88 KiB) Viewed 135 times

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

Re: Selecting multiple values from a option list

Post by odklizec » Fri Sep 14, 2018 12:33 pm

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

Noah
Posts: 5
Joined: Tue Aug 21, 2018 1:31 pm

Re: Selecting multiple values from a option list

Post by Noah » Fri Sep 14, 2018 1:55 pm

My bad haven't used the feature Ranorex snapshot.
please find the attached snapshot file.
Attachments
Option_value.rxsnp
(420.42 KiB) Downloaded 4 times

User avatar
N612
Posts: 62
Joined: Mon Jul 11, 2016 4:01 pm

Re: Selecting multiple values from a option list

Post by N612 » Fri Sep 14, 2018 7:45 pm

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
screenshot.png (11.08 KiB) Viewed 114 times

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

Re: Selecting multiple values from a option list

Post by odklizec » Mon Sep 17, 2018 8:10 am

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