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

How to select a List item in an unsorted list

2 Answers 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pieter
Top achievements
Rank 1
Pieter asked on 05 Aug 2015, 06:09 AM

Hi,

 So my process is rather simple, but for the life of me I can not get the list items clicked in the foreach statement.

This is what the code looks like

HtmlFindExpression FindMI = new HtmlFindExpression("id=~navCtrlInner" , "|", "Tagname=~ul");
            HtmlUnorderedList ul = myMgr.ActiveBrowser.Find.ByExpression<HtmlUnorderedList>(FindMI);

            foreach (HtmlListItem e in ul.Items)
            {
                Console.WriteLine(e.InnerText.ToString());
                Console.Read();
                e.MouseClick();
            }

 

it picks up the list items, I can see them in the console, but we are unable to select them.

Awaiting your replies with all my heart! :)

Thank you for reading

2 Answers, 1 is accepted

Sort by
0
Pieter
Top achievements
Rank 1
answered on 05 Aug 2015, 07:48 AM

Boommmm!!! I got this to work.

For those who want to know how here is the code now.

HtmlFindExpression mydiv = new HtmlFindExpression("id=~navCtrlInner", "|", "Tagname=~ul");
            HtmlUnorderedList myUl = myMgr.ActiveBrowser.Find.ByExpression<HtmlUnorderedList>(mydiv);

            foreach (HtmlListItem li in myUl.AllItems)
            {
                List<HtmlAnchor> mylista = new List<HtmlAnchor>();
                mylista.Add(li.Find.ByExpression<HtmlAnchor>("Tagname=~a"));

                foreach (HtmlAnchor a in mylista)
                {
                    Console.WriteLine(a.HRef.ToString());
                    Console.Read();
                    a.Click();
                }
            }

 this can be improved without a doubt but this is how I got it working!

Best regards

 

0
Boyan Boev
Telerik team
answered on 07 Aug 2015, 02:43 PM
Hello Pieter,

Happy to see it is working now.

If you need any additional assistance please let us know.

Regards,
Boyan Boev
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Pieter
Top achievements
Rank 1
Answers by
Pieter
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or