Xcelled194 28 Junior Poster in Training

OK, I'm making a program that pulls information out of a DaniWeb Profile page using a WebBrowser. However, it's frankly getting annoying having to click "Member log-in" each time, and this is something you'd do multiple times a day, possibly with different accounts. So, I thought, why not have it pop up the box automatically? Some digging into the HTML revealed this:

<a
 href="/forums/register.php" id="loginlink">Member
Log In</a>

<!--Annnd a little while later... -->

<script type="text/javascript"> <!--

$(function() {

$('a#loginlink').bind('click', function() {
$("#loginform").dialog( { modal: true });
return false;
});
//--> </script>

To my semi-trained eye, that looks like its intercepting the click event of the Login Link to show the custom dialog box. Great, I thought. I just need to simulate a click on that link.

Of course, the simple things never are. Here is the base code that triggers the box:

private void Form1_Load(System.Object sender, System.EventArgs e)
	{
            wbMain.ScriptErrorsSuppressed = true;
            //// skip error messages.
            ShowLoginBox();
	}
    private void ShowLoginBox()
    {
        
        wbMain.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wbMain_DocumentCompleted); //When the page loads, open login box.
        wbMain.Navigate(urlDaniWeb);
    }

    void wbMain_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        try
        {
            //OK, this is where everything is failing (I separated different attempts):

            //HtmlElement el = wbMain.Document.All["loginlink"];
            //el.InvokeMember("Click");
            //======================================================================
            //HtmlElement el = wbMain.Document.All["loginlink"];
            //el.InvokeMember("Click");
            //object obj = el.DomElement;
            //System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click");
            //mi.Invoke(obj, new object[0]);
            //======================================================================
            //HtmlElement btn = wbMain.Document.GetElementById("loginlink");
            //btn.InvokeMember("click"); 
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
        wbMain.DocumentCompleted -= wbMain_DocumentCompleted; //Unsubscribe, we don't want this going off like nuts
    }

Summary of the errors:

  • InvokeMember("Click") returns NULL, I even varied the case of Click.
  • System.Reflection.MethodInfo mi = obj.GetType().GetMethod("click"); mi is always NULL.

HOWEVER every method always successfully returns the link element, and manually clicking the link in the webbroswer does indeed bring up the box. As near as I can figure out, this link doesn't have the method "click"...?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.