How to change a drop-down list in a web browser control?

So, I have a list that I want to change that looks like this:

enter image description here

How to change the value of July? I need this to be 100% automated and change it to January. I have made many accounts on different sites and must change them all to the same date of birth. Yes, I know that I will need to find its ID, etc.

+4
source share
2 answers

Browse the HTML site and specify the id and values in the drop-down list, for example:

<select id="bdayMonthId" size="1" name="bdayMonth"> <option value="">Month</> <option value="Jan">January</> <option value="Feb">February</> <option value="Mar">March</> </select> 

To pre-select a dropdown value in a WebBrowser control, use this Winform code:

 webBrowser1.Document.GetElementById("bdayMonthId").SetAttribute("value", "Feb"); 
+5
source

I am a little confused about your question. If you just want to change an element in HTML, Jeremy's answer is the best and easiest way. If you want to invoke a JavaScript document, this should work:

Suppose the webbrowser document contains the following HTML:

 <html> <head> <title>Invoke Test</title> </head> <body> <div id="testdiv">Waiting...</div> <script> function changeDate(date) { var x=document.getElementById("testdiv"); x.innerHTML = date; } </script> </body> </html> 

To call the javascript JavaScript method for the web browser, you can use something like this:

 private void button1_Click(object sender, EventArgs e) { object o = webBrowser1.Document.InvokeScript("changeDate('june')"); } 

No need for System.Web, ASP, ScriptManagers or Interop. All the tools needed to manage the objects and events of the web browser and the document have a web browser control.

0
source

All Articles