4

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

enter image description here

How do I change the July value? I need this to be 100% automated and change it to January. I made a lot of accounts on various websites and need to change them all back to the same birthdate. Yes, I'm aware I'll have to find the ID of it, etc.

11
  • What technology? ASP.NET, MVC? What kind of DD, asp.net, DevExpress, telerik? Sep 1, 2012 at 3:12
  • My program is in C#. Is that what you're asking?
    – Jon
    Sep 1, 2012 at 3:15
  • 2
    C# is a programming language. You tagged this question "website". Controls like DropDownMenu differ depending on the type of web technology you are using. The web technology is what I'm looking for. Sep 1, 2012 at 3:19
  • I don't know... I'm using a WebBrowser control. I untagged website, I guess that's confusing.
    – Jon
    Sep 1, 2012 at 3:23
  • You want to automate a browser? What about Selenium? Sep 1, 2012 at 3:24

2 Answers 2

8

View the HTML of the website and identify the id and values of the dropdownlist, 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 the dropdownlist value in the WebBrowser control use this Winform code:

webBrowser1.Document.GetElementById("bdayMonthId").SetAttribute("value", "Feb");
0

I'm a bit confused about your question. If you just want to alter an element in the HTML, Jeremy's answer is the best, and simplest, way to go. If you wanted to call the document's javascript, this should work:

Let's assume that the webbrowser's 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 invoke the webbrowser document's javascript method, you can use something like this:

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

No System.Web, ASP, ScriptManagers or Interop are needed. All the tools you need to control webbrowser and document objects and events come with the webbrowser control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.