Capture JavaScript Popup text in webBrowser C#

时间:2015-12-10 01:38:59

标签: javascript c#

I have a webBrowser control on my C# forms app,which works perfectly. However, the url I am navigating to has JavaScript popups with text on them during interaction.

How do I capture the text on the JavaScript popup boxes? For example, the alert says "no more food" I want to capture the text "no more food" and pass to a label . below is my click event code and OnDocumentCompleted event handler

 private void iTalk_Button_21_Click(object sender, EventArgs e) //click event
    {
        Username = username.Text.Trim();
        Password=password.Text.Trim();
         webBrowser1.Navigate("someurl");
        webBrowser1.DocumentCompleted += WebBrowser1_DocumentCompleted;

        //MessageBox.Show(Username);
    }

    private void WebBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        tabControl1.SelectedTab = tabPage2;
        HtmlDocument doc = this.webBrowser1.Document;
        doc.GetElementById("ctl00_MainContent_Login1_UserName").SetAttribute("Value", Username);
        doc.GetElementById("ctl00_MainContent_Login1_Password").SetAttribute("Value", Password);
        doc.GetElementById("ctl00_MainContent_Login1_LoginButton").InvokeMember("click");
    }

0 个答案:

没有答案