Select item on List Item using code

Ask general questions here.
rj-nora
Posts: 38
Joined: Thu Mar 11, 2010 3:56 pm

Select item on List Item using code

Post by rj-nora » Tue Jun 01, 2010 3:26 pm

Hello ppl!

I'm using Ranorex last version at this moment and i need to ask you a question.
I have 1 List Item where i need to select and click on a certain date i.e "2008/11" if i do that using the recorder and convert that action to user code i have this method:

public static void Mouse_Click_ListItem2007_071()
{
//Your code here. Code inside this method will not be changed by the code generator.
Report.Info("Mouse Left Click item 'List1000.ListItem2007_07' at 50;3.");
repo.List1000.ListItem2008_011.Click("50;3");

}

But i need to receiving a date "2008/11" by a string i need to do the same but using code, without using record.It's possible?
Last edited by rj-nora on Mon Jun 07, 2010 9:56 am, edited 1 time in total.

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

Re: Select item on List Item using code

Post by Support Team » Wed Jun 02, 2010 11:37 am

Hi,

You can write your own method for this behavior. I think the method in following post should work for you after some modifications.
http://www.ranorex.com/forum/how-to-sel ... -t998.html

Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Thu Jun 03, 2010 1:19 pm

I still trying but with no success at this moment, can you show me a code snipet?
I have this code bellow not working...inside the if condition can i click on the option? How? With RanorexSpy i have the path for one date on the ComboBox : /form[@controlname='PPCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']/text[@accessiblevalue='2007/07']

public static void UserCodeMethod1()
{
string startDate = "{ListItem:2007/07}";
Ranorex.Form rtcForm = ("/form[@controlname='PPCMain']");
Ranorex.List RanorexList = rtcForm.FindSingle("/list[@controlid='1000']");
int count = RanorexList.Items.Count;
//Report.Error("Elementos da List Item"+ count);

foreach(Ranorex.ListItem fi in RanorexList.Items)
{

string f = fi.ToString();

//Report.Error(f);

if(f == startDate)
{
Report.Error("found item");
Last edited by rj-nora on Fri Jun 04, 2010 11:08 am, edited 3 times in total.

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

Re: Select item on List Item using code

Post by Support Team » Fri Jun 04, 2010 10:57 am

Hi,

I think following method is what you are searching for
public static void ClickItem(string strValue)
{
    foreach( Ranorex.ListItem item in Ranorex.List.Items )
    {
        if(item.Text == strValue)
        {
            item.Click();
        }
    }
}
Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Fri Jun 04, 2010 11:35 am

I will test it now, can you tell me if i can use the string = "2007/07" instead of {ListItem:2007/07} ?

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

Re: Select item on List Item using code

Post by Support Team » Fri Jun 04, 2010 11:40 am

Hi,

Just check the text with SPY, so you know the exact string of the list item.

Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Fri Jun 04, 2010 11:44 am

the full path of the combobox is /form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']

and the path of one element is :
/form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']/text[@accessiblevalue='2009/51']

i tried this code bellow and it didn't work(Ranorex.CapabilityNotSupportedException: The element does not support the required capability 'list'):

public static void ClickItem()
{
Ranorex.Form rtcForm = ("/form[@controlname='RTCMain']");
Ranorex.List RanorexList = rtcForm.FindSingle("/form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']");
string date = "{ListItem:2007/07}";

foreach( Ranorex.ListItem item in RanorexList.Items )
{
if(item.Text == date)
{

item.Click();
}
}
}


..

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

Re: Select item on List Item using code

Post by Support Team » Fri Jun 04, 2010 11:57 am

Hi,

Instead of
rj-nora wrote:Ranorex.List RanorexList = rtcForm.FindSingle("/form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']");
string date = "{ListItem:2007/07}";
use Ranorex.ComboBox
http://www.ranorex.com/Documentation/Ra ... mboBox.htm
Ranorex.ComboBox RanorexList = rtcForm.FindSingle("/form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']");
because you want to automate an combo box and not a list.

Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Fri Jun 04, 2010 11:58 am

Hi! i have already tried and when i play the test nothings happens...
Code:
public static void ClickItem()
{
Ranorex.Form rtcForm = ("/form[@controlname='RTCMain']");
Ranorex.ComboBox RanorexList = rtcForm.FindSingle("/form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']");
string date = "2007/07";

foreach( Ranorex.ListItem item in RanorexList.Items )
{
string itemFound = item.ToString();
Report.Error(itemFound);

if(item.Text == date)
{
Report.Error("INSIDE");
item.Click();
}
}
}

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

Re: Select item on List Item using code

Post by Support Team » Fri Jun 04, 2010 12:12 pm

Hi,

Please can you send us a Ranorex Snapshot.
http://www.ranorex.com/support/user-gui ... html#c2072
Or is it possible to send us the application to [email protected]

Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Fri Jun 04, 2010 12:17 pm

Here is the snapshot
ComboBox'comboBoxWeekFrom' = /form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']

element '2009/52' = /form[@controlname='RTCMain']/container[@controlname='myTimeSel']/container/tabpagelist/tabpage[@controlname='tabFiscalWeek']/container/combobox[@controlname='comboBoxWeekFrom']/text[@accessiblevalue='2009/52']
Attachments
ttt.rxsnp
(4.63 KiB) Downloaded 162 times
Last edited by rj-nora on Fri Jun 04, 2010 12:23 pm, edited 1 time in total.

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

Re: Select item on List Item using code

Post by Support Team » Fri Jun 04, 2010 12:23 pm

Hi,

There is no list below the combo box, this is the reason why you get this error
(Ranorex.CapabilityNotSupportedException: The element does not support the required capability 'list').
I think you have first to open the combo box then the list will be generated. So please try to open the combo box before you execute the foreach statement.

Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Fri Jun 04, 2010 12:28 pm

Thank you its starting to work

After do that on the Ranorex wrotte to the report every item like this :
2010/06/04 12:25:28.155 ERROR User {ListItem:1998/09}

2010/06/04 12:25:28.171 ERROR User {ListItem:1998/08}

But after that nothing happened...my string is string date = "2007/07"; the text[@accessiblevalue='2007/07'] i can't search for "2007/07"? it has to be {ListItem:1998/09}?

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

Re: Select item on List Item using code

Post by Support Team » Fri Jun 04, 2010 1:05 pm

Hi,

Please check the string value of the list item with SPY and use following string value for your method.

Regards,
Peter
Ranorex Support Team
.
Image

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

Re: Select item on List Item using code

Post by rj-nora » Fri Jun 04, 2010 2:41 pm

Thank you very much Problem solved ;)