ListItem with scrolbar ctrl key

Class library usage, coding and language questions.
rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

ListItem with scrolbar ctrl key

Post by rj-nora » Fri Jun 11, 2010 3:05 pm

Hello at this moment i needed to select 4 diferents items from a ListItem whith a scrolbar, using the recorder and it fails ...I haved to use user code to do that... Whith the Recorder i need to use the ctrl key to select the items but when i playback it fails...Exist any problem when recording drag the scrolbar with the control [ctrl] key pressed? I have to press the control key [ctrl] to select diferents items on the listItems....but i playback Ranorex makes very strange moves....
So i used that code, but the problem is the ctrl key....
Last edited by rj-nora on Tue Jun 15, 2010 10:10 am, edited 1 time in total.

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

Re: ListItem with scrolbar ctrl key

Post by Ciege » Mon Jun 14, 2010 4:16 pm

So what you'll need here is the following.
1) A list of items you want to click (I use a string array).
2) The listbox object .
3) The scroll bar object.

Once you have those you can loop through your items you want to click using a foreach. If this is your first item in the list, do a regular click else for each successive item to a control click.

The following is code I use to multi select values in a grid but you can change it just a bit to do multi select in a list box. Pay attention to the click section at the end for an idea of using the control key for multi select.

Code: Select all

public static int MultipleClickCellsInTable(Ranorex.Form RanorexFormName, Ranorex.Table HDTable, string[] strCellsTEXTToClick)
{
    try
    {
        HDTable.EnsureVisible();
        Ranorex.ScrollBar HDScrollBar = null;
        Ranorex.Button PageUp = null;
        Ranorex.Button PageDown = null;
        Ranorex.Button LineDown = null;

        RanorexFormName.Activate();

        //Get Parent Element
        Ranorex.Core.Element parentElement = HDTable.Element.Parent;

        //Check for the Vertical Scroll bar
        try
        {
            HDScrollBar = parentElement.FindSingle(".//element[@controltypename='VCrkScrollBar']/scrollbar[@accessiblename='scroll bar']", 30000);
            PageUp = HDScrollBar.FindSingle(".//button[@accessiblename='Page Up']", 30000);
            PageDown = HDScrollBar.FindSingle(".//button[@accessiblename='Page Down']", 30000);
            LineDown = HDScrollBar.FindSingle(".//button[@accessiblename='Line Down']", 30000);

            //Scroll to Top
            while (HDScrollBar.Value != 0)
            {
                PageUp.Click();
            }
        }
        catch (RanorexException e)
        {
            //No vertical Scroll Bar
        }

        RanorexFormName.Activate();
        int intItemCount = 0;
        foreach (string celltext in strCellsTEXTToClick)
        {
            //Search for the Resource Requested
            Ranorex.Cell RanorexCell = TableCellReturnCellObject(HDTable, celltext, "Resource Code");
            if (RanorexCell == null)
            {
                Report.Failure("Requested Resourece: " + celltext + " was not found in the Table.");
                return -1;
            }

            //Verify the Cell is Visible
            if (RanorexCell.Visible.ToString() == "False")
            {
                while (HDScrollBar.Value != 0)
                {
                    PageUp.Click();
                }
                while (RanorexCell.Visible.ToString() == "False")
                {
                    PageDown.Click();
                    Thread.Sleep(500);
                }
            }
            //Click the Cell
            Report.Debug("Left Clicking cell " + RanorexCell.Element.GetAttributeValue("AccessibleName").ToString());
            if (intItemCount > 0)
            {
                Keyboard.Press("{ControlKey DOWN}");
                RanorexCell.Click(Location.UpperCenter);
                Keyboard.Press("{ControlKey UP}");
            }
            else
            {
                RanorexCell.Click(Location.UpperCenter);
            }

            intItemCount++;
        }
        return 0;
    }
    catch (RanorexException e)
    {
        return -1;
    }
}
[/code]
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...

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

Re: ListItem with scrolbar ctrl key

Post by Support Team » Mon Jun 14, 2010 5:32 pm

rj-nora wrote:Exist any problem when recording drag the scrolbar with the control [ctrl] key pressed?
No, we don't know of an issue for such an action. Actually, I just tried to record selecting multiple items in a list using mouse and the Ctrl-key and did not have any problems - neither at selecting items, nor at scrolling.

To hold down the Ctrl-key just use the following two lines of code (see the documentation of the Mouse class):
Keyboard.Down(Keys.ControlKey);
// perform the mouse actions
Keyboard.Up(Keys.ControlKey);
Regards,
Alex
Ranorex Team
.
Image

rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Re: ListItem with scrolbar ctrl key

Post by rj-nora » Tue Jun 15, 2010 10:15 am

Support Team wrote:
rj-nora wrote:Exist any problem when recording drag the scrolbar with the control [ctrl] key pressed?
No, we don't know of an issue for such an action. Actually, I just tried to record selecting multiple items in a list using mouse and the Ctrl-key and did not have any problems - neither at selecting items, nor at scrolling.

To hold down the Ctrl-key just use the following two lines of code (see the documentation of the Mouse class):
Keyboard.Down(Keys.ControlKey);
// perform the mouse actions
Keyboard.Up(Keys.ControlKey);
Regards,
Alex
Ranorex Team
Thank you Ciege and Support Team , but when i use the control key while recording, after stop the action that appears is a SomeIndicator(Item Name) on the Record Tool, and when i playback the mouse lost its way selecting the items...For example selects the first one and after click down on ctrl key the action saved has the item name SomeIndicator instead of the normal action of drag the scrolbar down....

kkashyap1707
Posts: 10
Joined: Tue Jul 29, 2014 1:19 pm

Re: ListItem with scrolbar ctrl key

Post by kkashyap1707 » Wed Sep 24, 2014 12:35 pm

Will you please mention me how to page down in Mobile Web Automation using Ranorex RxBrowser.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: ListItem with scrolbar ctrl key

Post by krstcs » Wed Sep 24, 2014 2:20 pm

This thread is over 4 years old. Please do not resurrect old threads as it makes it difficult for the Ranorex support team to know what the actual issue is.

Second, your issue seems to be different than the one in this thread.

If you have an issue, create a new forum thread. If you want to reference an old thread, just mention it in your new thread.

Also, please include your Ranorex version, Windows version and any other relevant information in order to make it easier to help you with your issue.
Shortcuts usually aren't...