Run a FOR on Webbrowser C#

Asked

Viewed 59 times

0

I am currently trying to develop a data capture application using the WebBrowser of C#. I can get the application to enter the page and enter the value and click on search, but I can’t link this function to the loop for, for it to be executed repeatedly! I would like to know how I do. Below follows an example of the code I have:

 private void BTN_OPEMIE_Click(object sender, EventArgs e)
    {
            navegar();

            insert();

            BtnPesq();
    }

    public void navegar()
    {
        wb_1.Navigate("http://www3.prefeitura.sp.gov.br/smt/pesqveic/Pesquisa.aspx");

        while (wb_1.ReadyState != WebBrowserReadyState.Complete)
        {
            Application.DoEvents();
        }

    }

    public void insert()
    {
        wb_1.Document.GetElementById("txtplaca").SetAttribute("value", "ASD7534");

        wb_1.Document.GetElementById("btnPesquisar").InvokeMember("Click");


    }

    public void BtnPesq()
    {
        wb_1.Document.GetElementById("btnPesquisar").InvokeMember("Click");

        while (wb_1.ReadyState != WebBrowserReadyState.Complete)
        {
            Application.DoEvents();

        }

    }

The for would be at this stage of the code:

 private void BTN_OPEMIE_Click(object sender, EventArgs e)
{
     for(int i = 0; i < 10; i++)
      {
        navegar();

        insert();

        BtnPesq();
      }
}
  • Why isn’t it working?

  • So I put all the navigational commands of the webbrowser, inside a for loop, and the same is not executing the corresponding steps, ie in the first loop it must do a search, in the next one too and so on. What happens is that he is skipping the steps, that is he only makes the first consultation and the others not.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.