How to select a class by GetElementByClass and click on it programmatically

前端 未结 4 908
无人及你
无人及你 2020-12-11 06:23

I have been trying to use this code to read the element by class in html/ajax knowing GetElementByClass is not a option in webBrowser.Document. I can\'t seem to get a return

4条回答
  •  盖世英雄少女心
    2020-12-11 06:39

    this is a example of how i used the webbrowser control to find class specific elements and invoke Click on a link inside.

    simplified >

       foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("li"))
            {
                // use contains() if the class attribute is 
                // class="page_item page-item-218 current_page_item"
                //this to be more on spot! >> if (item.OuterHtml.Contains("class=\"page_item"))
                // or
                if (item.OuterHtml.Contains("page_item"))
                {
                    foreach (HtmlElement childItem in item.Children)
                    {
                        if (childItem.TagName == "A")
                        {
                            //Click the link/Current element
                            childItem.InvokeMember("Click");
                            break;
                        }
                    }
                    break;
                }
            } 
    

    does this way work ?..

    it works for me right here.

    or maybe i misunderstand your question?

提交回复
热议问题