Page 1 of 1

Select item on List Item using code

Posted: Tue Jun 01, 2010 3:26 pm
by rj-nora
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?

Re: Select item on List Item using code

Posted: Wed Jun 02, 2010 11:37 am
by Support Team
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

Re: Select item on List Item using code

Posted: Thu Jun 03, 2010 1:19 pm
by rj-nora
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");

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 10:57 am
by Support Team
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

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 11:35 am
by rj-nora
I will test it now, can you tell me if i can use the string = "2007/07" instead of {ListItem:2007/07} ?

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 11:40 am
by Support Team
Hi,

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

Regards,
Peter
Ranorex Support Team

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 11:44 am
by rj-nora
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();
}
}
}


..

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 11:57 am
by Support Team
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

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 11:58 am
by rj-nora
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();
}
}
}

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 12:12 pm
by Support Team
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

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 12:17 pm
by rj-nora
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']

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 12:23 pm
by Support Team
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

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 12:28 pm
by rj-nora
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}?

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 1:05 pm
by Support Team
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

Re: Select item on List Item using code

Posted: Fri Jun 04, 2010 2:41 pm
by rj-nora
Thank you very much Problem solved ;)