Updating ListItem setter with string value

Class library usage, coding and language questions.
jlowder
Posts: 55
Joined: Wed Dec 30, 2009 2:56 pm

Updating ListItem setter with string value

Post by jlowder » Mon Oct 31, 2011 8:36 pm

After a few years I'm back to using Ranorex, only this time I'm using it purely from Visual Studio 2010.

As part of my test I'm creating my own object repository, but instead of creating a new entry for each item in a list, I wanted to set a string value in the Xpath ID. Problem is, I can't pass in a string to a ListItem control via get/set.

My code looks like:

Code: Select all


        public ListItem Market
        {
            get
            {
                return Practice.FindSingle("/list[@controlid='1000']/listitem[@text='" + _Market + "']");
            }
                      
        }
Calling the object currently looks like:

Code: Select all

 myMaint.Market.Click();
What is the best way to pass in the "_Market" value to be clicked on?

Thanks,

Jason

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

Re: Updating ListItem setter with string value

Post by Support Team » Tue Nov 01, 2011 1:20 pm

jlowder wrote:What is the best way to pass in the "_Market" value to be clicked on?
You can either make the "_Market" a property itself, setting that property before calling "Market":
public string _Market
{
    get;set;
}
...
myMaint._Market = "yourValue";
myMaint.Market.Click();
Or you change "Market" to a method:
public ListItem Market(string textValue)
{
    return Practice.FindSingle("/list[@controlid='1000']/listitem[@text='" + textValue + "']");                     
}
...
myMaint.Market("yourValue").Click();
With Ranorex 3.X you can also use variables inside paths to change the value used for @text, however, you should then use Ranorex Studio to create a Ranorex Test Suite. See following chapter in the Ranorex User Guide:
http://www.ranorex.com/support/user-gui ... html#c2970

Regards,
Alex
Ranorex Team

jlowder
Posts: 55
Joined: Wed Dec 30, 2009 2:56 pm

Re: Updating ListItem setter with string value

Post by jlowder » Tue Nov 01, 2011 4:20 pm

Thanks, I was clearly over thinking it. :-)