VB.NET - Click Submit Button on Webbrowser page

前端 未结 8 713
时光说笑
时光说笑 2021-02-09 02:30

I have a html page open on my webbrowser object, I can enter username and password okay, but I\'m stuck and don\'t know how to submit the info. Here is the html code for the us

8条回答
  •  猫巷女王i
    2021-02-09 02:57

    This is my solution for something similar to this problem:

    System.Windows.Forms.WebBrowser www;
    
    void VerificarWebSites()
    {
        www = new System.Windows.Forms.WebBrowser();
        www.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(www_DocumentCompleted_login);
        www.Navigate(new Uri("http://www.meusite.com.br"));
    }
    
    void www_DocumentCompleted_login(object sender, WebBrowserDocumentCompletedEventArgs e)
    {            
        www.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(www_DocumentCompleted_login);
        www.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(www_DocumentCompleted_logado);
    
        www.Document.Forms[0].All["tbx_login"].SetAttribute("value", "Gostoso");
        www.Document.Forms[0].All["tbx_senha"].SetAttribute("value", "abcdef");
        www.Document.GetElementById("btn_login").Focus();
        www.Document.GetElementById("btn_login").InvokeMember("click");
    }
    
    void www_DocumentCompleted_logado(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        System.IO.StreamWriter sw = new StreamWriter("c:\\saida_teste.txt");
        sw.Write(www.DocumentText);
        sw.Close();
        MessageBox.Show(e.Url.AbsolutePath);
    }
    

提交回复
热议问题