views:

291

answers:

1

Hi,

I'm doing some web automation via C# and a WebBrowser. There's a link which I need to 'click', but since it fires a Javascript function, apparently the code needs to be executed rather than just having the element clicked (i.e. element.InvokeMember("click")). Here's the href for the element, which opens an Ajax form:

javascript:__doPostBack("ctl00$cphMain$lnkNameserverUpdate", "")

I've tried:

webBrowser1.Document.InvokeScript("javascript:__doPostBack", new object[] { "ctl00$cphMain$lnkNameserverUpdate", "" });

and:

webBrowser1.Document.InvokeScript("__doPostBack", new object[] { "ctl00$cphMain$lnkNameserverUpdate", "" });

and a few other things. The code gets hit, but the script doesn't get fired. Any ideas would be most appreciated.

Gregg

BTW Here's the full element in case it's useful:

<a href="javascript:__doPostBack('ctl00$cphMain$lnkNameserverUpdate','')" onmouseout="window.status=''; return true" onmouseover="window.status='Update Nameservers'; return true" id="ctl00_cphMain_lnkNameserverUpdate" onclick="javascript:Layout.ChangeIframeToSrc('DropinLoad_Domain.aspx?controlRequest=ActionNameserversWithIP');return false;">NS51.DOMAINCONTROL.COM<br/>NS52.DOMAINCONTROL.COM<br/></a>
A: 

Have a look at this link:

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting.aspx

I've actually used this in the past, and it works perfectly.

BFree
Thanks for the quick reply. It seems to do the trick. :-)
Gregg Cleland