Not able to perform multiple selection using Ctrl key

Ranorex Studio, Spy, Recorder, and Driver.
varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Not able to perform multiple selection using Ctrl key

Post by varun » Wed Sep 12, 2012 11:22 am

Hi Support,

I recorded selection of multiple options in List Box using ctrl key, It's works fine if I play it simply.
But I am not able to perform Data Driven multiple selection of records with it.

Note: I have defined data driven values in excel(as Data source) and want RX to select those values by scrolling down or up automatically.

Please let me know the complete solution of it including code snippets. Even I want to know how & where I can do scripting in RX ?


Thanks in advance,
Varun.

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Thu Sep 13, 2012 12:54 pm

Hi Support Team,

Please provide solution for this problem, I will be grateful to you :!:

WR,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Not able to perform multiple selection using Ctrl key

Post by Support Team » Thu Sep 13, 2012 2:56 pm

Hi Varun,

In general you have to check if the "elements", you want to select, are in the visible area and if not you have to scroll. For this case the Visible Attribute would be of great use.
Since we have no access to your application we cannot provide a full solution to your problem, we just can
point you in the right direction.
Here are some links about how to write UserCode: User Code Actions, Lesson 7: Code Modules, Code Examples.

I hope this helps,
Markus
Ranorex Support Team

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Fri Sep 14, 2012 10:09 am

Hi Markus,

You are correct that we have to look for the visible area. But afraid to say that, didn't get much from the provided links.
For your reference, I am attaching the RX snapshot of List Box. Please review and let me know in detail the solution for this.

WR,
Varun.
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Not able to perform multiple selection using Ctrl key

Post by Support Team » Mon Sep 17, 2012 4:06 pm

Hi,

Thanks for the Snapshot.
I would check if the option tag you want to select is visible and if it is visible I would just select it and if not I would call the EnsureVisible method of the element in order to bring it in the visible area.
Did you already try it this way?

Regards,
Markus
Ranorex Support Team

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Tue Sep 18, 2012 5:41 am

Hi Markus,

Thanks for your reply.
I tried but unable to fetch records from excel. So please let me know that at which step should I enter code snippet and how records can be fetched from excel to check if related record is in visible area or not ?

WR,
Varun

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Tue Sep 18, 2012 12:57 pm

Hi Support,

I rephrase my question here again for more clarity on requirement.

I am creating automated script for Web form which has Week days List-box i.e Monday, Tuesday, Wednesday...Automated script runs ok with recorded values in Listbox. I have created Excel for selection of Multi-choices for eg. Monday and Wednesday i.e. (1,3). When I run the script, it selects days as first Monday and then Wednesday. But while selection of Wednesday, it deselects Monday so it means it doesn't work with multiple item selection.
I am looking for the solution of this problem. I have already attached Ranorex snapshot of listbox in earlier replies. Additionally, I am attaching Excel snapshot for your information.

Please take this on high priority.

Thanks in advance!

Varun
You do not have the required permissions to view the files attached to this post.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Not able to perform multiple selection using Ctrl key

Post by Ciege » Tue Sep 18, 2012 4:42 pm

Are you making your 2nd and successive clicks with the CTRL key down?

Something like this pseudo code....

Code: Select all

itemCount = 0
foreach ItemToSelect in ListOfItemsToSelect
{
  if itemCount = 0
    //click with no keys down so that only the first item is selected clearing any potential other selection 
    Click ItemToSelect
  else
  {
    //Click with the control key down so 2nd++ selections are multi-selected
    Keyboard.Press("{ControlKey DOWN}");
    Click ItemToSelect
    Keyboard.Press("{ControlKey UP}");
  }
  itemCount ++;
}
  
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Wed Sep 19, 2012 5:43 am

Hello Ciege,

Thanks for the code, it will help us for attaining our task. :)
Yes, we have to make 2nd and successive clicks with CTRL key down. But it should select only those items which are provided in Excel(attached in previous reply). For e.g, For first iteration, Items with values 1& 2 should be selected. For second iteration, Items with values 2, 4 & 5 should be selected. And similarly for Iteration 3, Items with values 1 & 5 should be selected.
Note: Also it should be verified that Items are in visible area or not. If not, then scroll down/up to make it visible and then should select it.

Thanks,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Not able to perform multiple selection using Ctrl key

Post by Support Team » Wed Sep 19, 2012 10:48 am

Hi,

You can add another if clause where you have to check if the specific item is visible or not:
foreach Item to select
			{
				
				if item is not visible{
					//make item visible with for instance with EnsureVisible
					item.EnsureVisible()
				}
...
Regards,
Markus
Ranorex Support Team

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Wed Sep 19, 2012 12:42 pm

Hi Markus,

Thanks for Code Snippet !
My concern is for getting records from Excel. As mentioned in previous reply, for 1st iteration I want 2 days to be selected for which values are defined in Excel separated by comma. So first of all tell me will it work(values in excel separated by comma) and secondly, if excel format is accurate then can RX fetch excel records normally or we need to define code for it ??

Kindly remember, as Ciege identified that selection should be with CTRL for 2nd and successive clicks.

Let me know, If any thing I am left with.

Thanks in advance,
Varun.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Not able to perform multiple selection using Ctrl key

Post by Ciege » Wed Sep 19, 2012 4:02 pm

So do you already have an implementation ready for reading data from Excel?
You can either use the dataconnector functionality provided by Ranorex, or possibly the COM implementation I shared here: http://www.ranorex.com/forum/my-excel-f ... t3265.html, or any other methods for getting data from Excel.

Once you have read the cell that contains your test data, you can parse it (in your case by comma) and assign those values to the list I represented in my above snippet of code called "ListOfItemsToSelect".
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: Not able to perform multiple selection using Ctrl key

Post by varun » Thu Sep 20, 2012 1:59 pm

Hi Ciege,

Thanks for you feedback :)
Please review code provided in attached text file, which read values form excel and then execute through RX. It fails while executing through RX. Please guide.
MultipleSelection_20120920.txt
For your reference, I have also attached snapshot for errors that I am getting while executing the code.


Waiting for your response.

Thanks & Regards,
Varun.
You do not have the required permissions to view the files attached to this post.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Not able to perform multiple selection using Ctrl key

Post by Ciege » Thu Sep 20, 2012 4:26 pm

Snippet of your code:

Code: Select all

Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();

Excel.Workbook xlWorkBook = (Excel.Workbook)xl.Workbooks.Open(@"D:\Varun Docs\Ranorex\TestRanorex\TryMultipleSelection-ListItem.xls");//, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
        	
Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets[1];

Excel.Range r  = (Excel.Range)xlWorkSheet.get_Range("A2","A4");
//MessageBox.Show(r.Value.ToString());
foreach (r.Value in xlWorkBook)
{
  if (itemcount = 0)
  {
    click r.Value;
  }
  else
  {
    Keyboard.Press ("{controlkey Down}");
    click r.Value;
    Keyboard .Press ("{controlkey up}");
  }
  itemcount++;
}
Your error states that you need a type and identifier in your foreach statement...

To solve this, 1st you need to get a string array of the data in your range.
So after this line

Code: Select all

Excel.Range r  = (Excel.Range)xlWorkSheet.get_Range("A2","A4");
you need to get the data from the cell range:

Code: Select all

System.Array myvalues = (System.Array)r.Cells.Value2;
Then you need to convert that array to something you can work with like a string array:

Code: Select all

string[] strArray = ConvertToStringArray(myvalues);
Finally you can foreach through the string array:

Code: Select all

foreach (string str in strArray)
{
  Console.WriteLine(" Text in cell " + str);
}
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...