C# web browser select list item click

2019-06-17 18:06发布

问题:

I am trying to select item from select list box using this method:

  var elements = webBrowser1.Document.GetElementsByTagName("select");



        foreach (HtmlElement element in elements)
        {

            if (element.GetAttribute("id")=="pagesize")
            {
                element.GetElementsByTagName("option")[2].SetAttribute("selected", "selected");
                webBrowser1.Document.InvokeMember("click");
            }
        }

from this html code

<select name="pagesize" id="pagesize" onchange="changeFileListRequestSize();">
                <option value="10">10 files per page</option>
                <option value="25" selected="selected">25 files per page</option>
                <option value="50">50 files per page</option>
                <option value="100">100 files per page</option>
                <option value="200">200 files per page</option>
            </select>

item is actually changes but that's doesn't execute onchange="changeFileListRequestSize();" javascript event.

how to simulate select list item click or "change"

回答1:

document.GetElementById("pageSize").InvokeMember("onchange")