How to simulate the click of a button with httpWebRequest

Asked

Viewed 74 times

-1

This code of mine takes an entire content specific to a site How to simulate the click of a button?

[Route("HomeController/Requisicao")] // Matches 'Products/Index'
            public string Requisicao()
            {
                var result = "";
                string path = "http://testedev-rpa.ddns.net";
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(path);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method = "POST";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {


                    streamWriter.Write(true);
                    streamWriter.Flush();
                    streamWriter.Close();

                    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        result = streamReader.ReadToEnd();
                    }

                }

                return result;
            }

1 answer

0

I do something similar using Webbrowser to take an element of an HTML and invoke the click of it. Example:

var botao = webBrowser.Document.GetElementById("id_do_botao");
botao?.InvokeMember("click");

Make sure you can take the HTML that is returned to you and pass it to a Webbrowser.

  • Yeah, I’m using Selenium for this, but it’s giving me an error of the eviroment path of it, even though I’m downloading the Chrome driver

Browser other questions tagged

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