WebBrowser - unable to retrieve and set HTML elements in an .asp page which is called

落花浮王杯 提交于 2019-12-02 07:07:56

You can use webBrowser.Document.Window.Frames["main"].Document to get to the inner frame's document. The following works for me:

private async void MainForm_Load(object sender, EventArgs e)
{
    var tcs = new TaskCompletionSource<bool>();
    WebBrowserDocumentCompletedEventHandler handler = (s, arg) => 
        tcs.TrySetResult(true);

    this.webBrowser.DocumentCompleted += handler;
    this.webBrowser.Navigate("http://localhost:81/frameset.html");
    await tcs.Task;
    this.webBrowser.DocumentCompleted -= handler;

    var frameDocument = this.webBrowser.Document.Window.Frames["main"].Document;
    var element = frameDocument.GetElementById("CorporateSignonCorpId");
    MessageBox.Show(element.OuterHtml);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!