This is a migrated thread and some comments may be shown as answers.

Trying to iterate through a list and select each value

1 Answer 282 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 14 Mar 2014, 12:13 PM
I have a dropdown in my webapp with a number items listed.

<ul id="ShowOptions" > 
  <li id="ShowOption1">Item1</li>
  <li id="ShowOption2">Item2</li>
  <li id="ShowOption3">Item3</li>
  <li id="ShowOption4">Item4</li>
</ul>

I want to iterate through each of the items, select one and then press a button on my page after each selection.

The code I have so far grabs each element in the list but i'm not sure where to go from there.

HtmlUnorderedList showoptions = ActiveBrowser.Find.ById<HtmlUnorderedList>("Show Options"); 

foreach(HtmlListItem item in showoptions.AllItems)
{    
        //Do stuff
}

1 Answer, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 19 Mar 2014, 11:51 AM
Hi Kevin,

Here is the code how you can click on an item base on its text:

HtmlUnorderedList list = ActiveBrowser.Find.ById<HtmlUnorderedList>("ShowOptions");
            foreach (HtmlListItem item in list.AllItems)
            {
                if (item.TextContent == "Item3")
                    item.Click();
            }

Let me know if this helped.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Kevin
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Share this question
or