Home > DeveloperSection > Forums > C# - Access variable Names dynamically
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    January-31-2014 11:26 PM

 C# C# 

 1 Reply(s)
 1191  View(s)
Rate this:

I am automating a web page. i have captured and saved the Links in a file.

Link Url_0="gmail.com"

Link Url_1="ymail.com"

Link Url_2="hotmail.com"

Link Url_3="outlook.com"

The below statement will click on each url.

HomePage.Url_0.Click();//Homepage is the Class name

I want to Click these URLs one by one. So I am using a for loop.

for(int i=0;i<3;i++)


String url=String.Format("Url_{0}",i);

HomePage.url.Click(); //This is throwing me error (I think that this is not correct way to do.)



How can I proceed here ? Can this be done in any way ? Any help is appreciated.

Pravesh Singh

Total Post:412

Posted on    January-31-2014 11:41 PM

Hi Jay,

You can store all links you want into a Coolection of type: IList<Link> or into an IEnumerable<Link>

IList<Link> myCollection = new List<Link>();

After that, you'll go throuh items in the collection with an

foreach(var item in myCollection ) {

      //Here implement your logic with click


Don't want to miss updates? Please click the below button!

Follow MindStick