Click on hidden item in listbox

Ask general questions here.
erman
Posts: 15
Joined: Tue May 15, 2012 3:53 pm

Click on hidden item in listbox

Post by erman » Tue May 15, 2012 3:59 pm

Hi All,

I am new to Ranorex and I have a question concerning listbox objects. I was going through the tutorial (VIP Database) and I was unable to automate the select of a category (i.e. Sport) from the Category listbox, since the item is not displayed (must click down on the scroll bar) once the application is launch. Using C#, how would one handle this situtation?

Thanks for any help!
Eric

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

Re: Click on hidden item in listbox

Post by Support Team » Wed May 16, 2012 4:15 pm

Hi,

therefore please have a look at following chapter of our user guide, which explains how to handle such a scenario:
Executing Data Driven Test

Regards,
Tobias
Ranorex Team

erman
Posts: 15
Joined: Tue May 15, 2012 3:53 pm

Re: Click on hidden item in listbox

Post by erman » Wed May 16, 2012 9:47 pm

Hi,

I have done the "invoke action" using the method described in the document, but my question was how would I do the equivalent using C# code?

Thanks,
Eric

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

Re: Click on hidden item in listbox

Post by Support Team » Thu May 17, 2012 1:40 pm

erman wrote:I have done the "invoke action" using the method described in the document, but my question was how would I do the equivalent using C# code?
If you want to see the code of this action, you just have to look in the generated recording file or you convert this action to user code. To convert this action just right-click the action and then use the context menu to do the conversion.

Regards,
Peter
Ranorex Team

t4k9
Posts: 10
Joined: Wed Mar 07, 2012 11:00 pm

Re: Click on hidden item in listbox

Post by t4k9 » Wed Aug 01, 2012 11:08 pm

Hi,

We have a similar issue, however we only have a license to the Ranorex API and not the studio.

How can we get all the items in a listbox if for example there are 1000 items but only 10 are visible at a time, ranorexListBox.Items returns only the visible items.

We need this functionality for many reasons, some of which:
we would like to be able to select an item at index 950 for example
we would like to output all items
...

Thanks

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

Re: Click on hidden item in listbox

Post by Support Team » Thu Aug 02, 2012 10:17 am

Hi,

To get all the items of a list you can do the following:
List list = "/form[@controlname='Form1']/list/list[@accessiblerole='List']";
IList<ListItem> items = list.Items;
Now you can operate with those items like you will do with ordinary list items.
Example: Select item with index 950:
items[950].Select();
Example: Output all items:
foreach(ListItem item in items)
     Report.Info("List:",item.Text);
Regards,
Larissa
Ranorex Support Team

ABSciex
Posts: 5
Joined: Thu Aug 02, 2012 4:07 pm

Re: Click on hidden item in listbox

Post by ABSciex » Thu Aug 02, 2012 4:13 pm

This is the problem we are actually facing.

list.Items does not return all the 1000 items in the listbox but rather only the 8 - 10 visible items. scrolling up or down the listbox refreshes list.items with the new visible items but erases the old ones.

P.S. we are testing a WPF application.

Please help use solve this critical issue,
Thanks

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

Re: Click on hidden item in listbox

Post by Ciege » Thu Aug 02, 2012 5:47 pm

It sounds like your AUT has the list "lazy loaded". In other words the element only loads the items when they are needed (i.e. until they are scrolled into view). This is an implementation of the AUT controls and not a limitation of Ranorex. To work this issue make sure to check for scrollbars when reading the data and then scroll the items into view and compile your own list of what items are in your element.

You will need to write you own method to do this... Something like the pseudo code to follow:

Pseudo Code:

Code: Select all

//Click your ListBox open button
Listbox.OpenButton.Click;
try
  {//check for a scrollbar in the listbox
  scrollbarelement = Listbox.FindSingle(.//scrollbar)
  //if found get the up & down buttons
  scrollbarfound = true;
  Scrollbar.PageupButton = Listbox/Findsingle(.//scrollbar/button(@text = 'pageup'));
  Scrollbar.DownButton = Listbox/Findsingle(.//scrollbar/button(@text = 'Down'));
  while (scrollbarelement.value != 0)
    {//make sure the scroll bar is all the way up
    PageupButton.click();
    }

  //Scroll down the listbox by clicking the down button until the item you want selected is selected
  while (MyItem.selected = false)
    {
    DownButton.Click;
    }
  }
catch
{scrollbarfound = false;}

//Click the item you want clicked
MyItem.Click


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

ABSciex
Posts: 5
Joined: Thu Aug 02, 2012 4:07 pm

Re: Click on hidden item in listbox

Post by ABSciex » Thu Aug 02, 2012 10:15 pm

Thanks for the suggestion.

First of all Ranorex does not recognize the scroll bar inside a listbox, so there is no way of getting a handle to it.
If we could get a handle to it and follow the suggested approach we would also have to store the position of the listitem relative to the scrollbar because there would not be a way of clicking on it unless its active and on the screen. trying to focus on a listitem that is not active/ not visible results in an exception.

Is there an easier way?

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

Re: Click on hidden item in listbox

Post by Ciege » Thu Aug 02, 2012 10:36 pm

ABSciex wrote:Is there an easier way?
Um, another way could be strictly keyboard driven... Similar to above...

1) Open the listBox
2) KeyboardPress CTRL-HOME to go to the top of the list
3) KeyboardPress Down Arrow until the item you want is selected
4) Click Item...
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...

ABSciex
Posts: 5
Joined: Thu Aug 02, 2012 4:07 pm

Re: Click on hidden item in listbox

Post by ABSciex » Tue Aug 07, 2012 9:34 pm

This worked well.

Thanks!

ABSciex
Posts: 5
Joined: Thu Aug 02, 2012 4:07 pm

Re: Click on hidden item in listbox

Post by ABSciex » Wed Aug 08, 2012 1:22 am

I encountered a problem using this method and I just cant seem to figure out what's going on...

I am trying to store all the ListItems into a list
here is what I do:

1. go to start of ListBox - ctrl+home
2. if ListBox is empty return
3. while there are items: take the current item ( that is the item that is currently focused ) and add to the list, like so:

ListItem currentItem = _rexList.Items.First(item => item.HasFocus);
_list.Add(currentItem);

4. go down 1 item - ctrl+down

The problem: Sometimes there are no focused items found and i get an exception in step #3... at random times!

Whats going on here?

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

Re: Click on hidden item in listbox

Post by Support Team » Wed Aug 08, 2012 12:58 pm

Hi,

Could it be that you forgot to select an item respectively are you sure the first item is always the selected one?
A Ranorex Snapshot file of your List or even better a small sample which contains that list would help us analyzing the issue.
Following link will show you how to generate a snapshot file:
Creating Ranorex Snapshot Files

Regards,
Markus
Ranorex Support Team

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

Re: Click on hidden item in listbox

Post by Ciege » Wed Aug 08, 2012 3:33 pm

ABSciex wrote:I encountered a problem using this method and I just cant seem to figure out what's going on...

I am trying to store all the ListItems into a list
here is what I do:

1. go to start of ListBox - ctrl+home
2. if ListBox is empty return
3. while there are items: take the current item ( that is the item that is currently focused ) and add to the list, like so:

ListItem currentItem = _rexList.Items.First(item => item.HasFocus);
_list.Add(currentItem);

4. go down 1 item - ctrl+down

The problem: Sometimes there are no focused items found and i get an exception in step #3... at random times!

Whats going on here?
Couple of things to check...
1) for step 4, you should use a down arrow instead of CTRL-DOWN to go down 1 item at a time... CTRL-DOWN will send you to the bottom of your list.
2) Insert a small delay in your loop between downs, like a 1/2 to 1 second or so. Sometimes Ranorex can run faster than your AUT can respond.
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...

ABSciex
Posts: 5
Joined: Thu Aug 02, 2012 4:07 pm

Re: Click on hidden item in listbox

Post by ABSciex » Wed Aug 08, 2012 4:53 pm

Support Team wrote:Hi,

Could it be that you forgot to select an item respectively are you sure the first item is always the selected one?
A Ranorex Snapshot file of your List or even better a small sample which contains that list would help us analyzing the issue.
Following link will show you how to generate a snapshot file:
Creating Ranorex Snapshot Files

Regards,
Markus
Ranorex Support Team
I am actually not selecting any items i'm just focusing over them, this is to ensure i don't modify the previously selected ListItems in case I want to get all selected items at a later point. P.S. we do not have license to the studio. We are writing all our code using the API.

Here is a snap shot of the code, this pieace of code is suppose to go through all the items and add up all the ListItem to list

// go to start
_rexList.Focus();
_rexList.EnsureVisible();
Keyboard.Down(Keys.ControlKey);
Keyboard.Down(Keys.Home);
Keyboard.Up(Keys.Home);
Keyboard.Up(Keys.ControlKey);

// check ListBox is not empty
if (_rexList.Items.Count < 1)
return;

while (true)
{
// add the currently focused item to a IList<string>
ListItem currentItem = this._rexList.Items.First(item => item.HasFocus);
_list.Add(currentItem);

//check if reached end of list
ListItem relativeLast = _rexList.Items.Last(); // will be changing until truly becomes last, due to lazy loading
if(relativeLast.HasFocus)
break;

// go down 1 item
Keyboard.Down(Keys.ControlKey);
Keyboard.Down(Keys.Down);
Keyboard.Up(Keys.Down);
Keyboard.Up(Keys.ControlKey);
}
Couple of things to check...
1) for step 4, you should use a down arrow instead of CTRL-DOWN to go down 1 item at a time... CTRL-DOWN will send you to the bottom of your list.
2) Insert a small delay in your loop between downs, like a 1/2 to 1 second or so. Sometimes Ranorex can run faster than your AUT can respond.
Ctrl-down moves thefocus to the next ListItem. down moves the selected item to the next ListItem, I dont want to do this, this overrides the previously selected items.
I will try adding a delay like you suggested. Thanks.