How to select a List item in an unsorted list

3 posts, 0 answers
  1. Pieter
    Pieter avatar
    8 posts
    Member since:
    Jul 2015

    Posted 05 Aug 2015 Link to this post

    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. Pieter
    Pieter avatar
    8 posts
    Member since:
    Jul 2015

    Posted 05 Aug 2015 Link to this post

    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

     

  3. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 07 Aug 2015 Link to this post

    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
     
Back to Top