Element is not working on ListView and Edit box

Class library usage, coding and language questions.
Nik
Posts: 18
Joined: Fri Sep 29, 2006 1:35 am

Element is not working on ListView and Edit box

Post by Nik » Fri Oct 06, 2006 11:10 pm

Hi,
The element approach of selecting item one at a time is not working on ListView and Edit. Are there any known issues or it is not supported.
I am using the same code you suggested for navigating in the Listbox.
The code is failing when I use
if ( RxElementFindChild(&element, ROLE_SYSTEM_OUTLINE, NULL, NULL, &editBoxElement) == TRUE )

Please suggest.

I also want to know the way to retrieve the items which are selected in a ListView. For e.g. I have a listview having 10 items. Out of which item 2,5,7 are selected(highlighted). How can I know using Ranorex API that items 2,5,7 are selected.

Thanks.
Nikhil

webops
Site Admin
Site Admin
Posts: 349
Joined: Wed Jul 05, 2006 7:44 pm

Post by webops » Sat Oct 07, 2006 11:09 am

You should use ROLE_SYSTEM_LIST for the list view and ROLE_SYSTEM_LISTITEM for the items (see RanorexSpy).

Here are some C++ code samples:
(Tested with VS2005Application.exe)

Find and select a list item with the name Test2 in a list view:

Code: Select all

ElementStruct listItem;
BOOL bRet = RxElementFindChild(&element, ROLE_SYSTEM_LISTITEM, "Test2", NULL, &listItem);
if (bRet==TRUE)
{
    printf("    List item found\n");
    RxElementSelect(&listItem, SELFLAG_TAKEFOCUS | SELFLAG_TAKESELECTION);
    RxSleep(500);
}
Dump out and select all list items in a list view:

Code: Select all

ElementStruct listElement;
if ( RxElementFindChild(&element, ROLE_SYSTEM_LIST, NULL, NULL, &listElement) == TRUE )
{
    int childCount = RxElementGetChildCount(&listElement);
    for(int i=0; i< childCount; i++)
    {
        if ( RxElementGetChild(&listElement, i, &listItem) == TRUE )
        {
            printf("    Item(%d)=%s\n",i,listItem.Name);
            RxElementSelect(&listItem, SELFLAG_TAKEFOCUS | SELFLAG_TAKESELECTION);
            RxSleep(300);
        }
    }
}
Get the selection flag of the list view items:

Code: Select all

ElementStruct listElement;
if ( RxElementFindChild(&element, ROLE_SYSTEM_LIST, NULL, NULL, &listElement) == TRUE )
{
    int childCount = RxElementGetChildCount(&listElement);
    for(int i=0; i< childCount; i++)
    {
        if ( RxElementGetChild(&listElement, i, &listItem) == TRUE )
        {
            int state = RxElementGetState(&listItem);
            if( state & STATE_SYSTEM_SELECTED) 
                printf("    Item(%d)=%s selected\n",i,listItem.Name);
            else
                printf("    Item(%d)=%s not selected\n",i,listItem.Name);
            RxSleep(300);
        }
    }
}
Jenö Herget
Ranorex Team