Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser Control - Invoke Script Problems with JavaScript Button

I am trying to login to a website. I am able to fill out the form correctly with all of the connection information, but I cannot get the page to login. The button is a link without a name or id, so I can't click it directly. I have been working on invokeScript() stuff, but that doesn't seem to work either. This is the button code:

<div style="float:left; width:50px; margin: 0px auto 0px auto; text-align:center;">
    <div id="loginBtn">
        <a href="#" style="text-decoration:none; font-weight:bold; font-size: 10px; color:#FFFFFF;" onClick="javascript: LoginSubmit(event, true);" tabindex="3">
            Log In
        </a>
    </div>
</div>

How can I click a link like that?

I have tried stuff like this:

webBrowserControl.InvokeScript("LoginSubmit", "true" );

webBrowserControl.InvokeScript("LoginSubmit(event, true)"); 

and

webBrowserControl.InvokeScript("LoginSubmit", new object[] { new string[] { "event", "true" } });
like image 781
Nathan Tornquist Avatar asked Jun 20 '26 08:06

Nathan Tornquist


1 Answers

You may be missing Document, like so:

webBrowserControl.Document.InvokeScript(name, args)

if not try invoking the script with this wrapper method, extract:

private object MyInvokeScript(string name, params object[] args) 
{ 
    return webBrowserControl.Document.InvokeScript(name, args); 
}

…

int x = 50; 
int y = 100; 
MyInvokeScript("LoginSubmit",x, y);
like image 165
m.edmondson Avatar answered Jun 22 '26 23:06

m.edmondson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!