c# - Form submit issue when invoking click? -
i'm trying make small program loads webpage form submits form on page automaticlly - apart of larger project cant part work properly.
this web page offer court cases results when correct case number , date (mm-yy) typed in , submitted.
i created simple webbrowser in form , called webbrowser1
.
and here form.cs code:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading; using system.windows.forms; namespace windowsformsapplication1 { public partial class form1 : form { public form1() { initializecomponent(); webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(handlerequest); firststep(); // secondstep(); } private void firststep() { webbrowser1.url = new system.uri("http://www.court.gov.il/ngcs.web.site/homepage.aspx", system.urikind.absolute); } private void handlerequest(object sender, webbrowserdocumentcompletedeventargs e) { webbrowser1.documentcompleted -= new webbrowserdocumentcompletedeventhandler(handlerequest); htmlelement casenumber = ((webbrowser)sender).document.all["header1_caselocatorheaderuc2_bamacasenumbertextboxht"]; htmlelement casedate = ((webbrowser)sender).document.all["header1_caselocatorheaderuc2_bamamonthyeartextboxht"]; casenumber.focus(); system.windows.forms.sendkeys.send("(1)"); system.windows.forms.sendkeys.send("(2)"); system.windows.forms.sendkeys.send("(2)"); system.windows.forms.sendkeys.send("(3)"); system.windows.forms.sendkeys.send("(8)"); system.windows.forms.sendkeys.send("{tab}"); system.windows.forms.sendkeys.send("(0)"); system.windows.forms.sendkeys.send("(3)"); system.windows.forms.sendkeys.send("(1)"); system.windows.forms.sendkeys.send("(0)"); htmlelement inputtag = webbrowser1.document.all["header1_caselocatorheaderuc2_searchheadercasebutton"]; inputtag.invokemember("click"); } } }
as can see - i'm typing values shown in picture , invoking click on button submits form, doesn't work!? webpage tricky , uses scripts validate input , sets correct values submits , way works on ie < 10....
any idea please?
edit: working - firing invoke
twice don't have idea problem.
now new problem added button click fires process btnget_click
, when triggering function error - seems detailstag
set null... when un-comment function in public form1()
working fine , loading website should.
what difference between calling the function firststep()
in button click / public form?
why receive error?
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading; using system.windows.forms; namespace windowsformsapplication1 { public partial class form1 : form { private readonly object lock_ = new object(); htmlelement casenumber; htmlelement casedate; htmlelement detailstag; int checks = 1; public form1() { initializecomponent(); //webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(handlerequest); //firststep(); } private void firststep() { webbrowser1.url = new system.uri("http://www.court.gov.il/ngcs.web.site/homepage.aspx", system.urikind.absolute); } private void handlerequest(object sender, webbrowserdocumentcompletedeventargs e) { if (checks < 1) { webbrowser1.documentcompleted -= new webbrowserdocumentcompletedeventhandler(handlerequest); webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(getdetails); } casenumber = ((webbrowser)sender).document.all["header1_caselocatorheaderuc2_bamacasenumbertextboxht"]; casedate = ((webbrowser)sender).document.all["header1_caselocatorheaderuc2_bamamonthyeartextboxht"]; if (casenumber != null && casedate != null) { casenumber.focus(); system.windows.forms.sendkeys.send("(5)"); system.windows.forms.sendkeys.send("(6)"); system.windows.forms.sendkeys.send("(5)"); system.windows.forms.sendkeys.send("(8)"); system.windows.forms.sendkeys.send("{tab}"); system.windows.forms.sendkeys.send("(0)"); system.windows.forms.sendkeys.send("(8)"); system.windows.forms.sendkeys.send("(1)"); system.windows.forms.sendkeys.send("(3)"); checks = 0; system.windows.forms.sendkeys.send("{enter}"); } else { messagebox.show("no such case - enter new one"); } } private void getdetails(object sender, webbrowserdocumentcompletedeventargs e) { webbrowser1.documentcompleted -= new webbrowserdocumentcompletedeventhandler(getdetails); webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(getresults); detailstag = webbrowser1.document.all["_ctl0_casedetailsgrid_row1_ct6_imagebutton1"]; if (detailstag != null) { detailstag.invokemember("click"); } else { messagebox.show("error - try case!"); } } private void getresults(object sender, webbrowserdocumentcompletedeventargs e) { webbrowser1.documentcompleted -= new webbrowserdocumentcompletedeventhandler(getresults); htmlelement detailsstatus = webbrowser1.document.all["_ctl7_casestatusidlbl"]; htmlelement detailscourt = webbrowser1.document.all["_ctl7_courtidlbl"]; htmlelement detailstype = webbrowser1.document.all["_ctl7_casetypeidlbl"]; htmlelement detailsamount = webbrowser1.document.all["_ctl7_claimamountlbl"]; htmlelement detailsprev = webbrowser1.document.all["_ctl7_privilegeidlbl"]; txtamount.text = detailsamount.innertext; txtcount.text = detailscourt.innertext; txtprev.text = detailsprev.innertext; txtstatus.text = detailsstatus.innertext; txttype.text = detailstype.innertext; } public void btnget_click(object sender, eventargs e) { webbrowser1.documentcompleted += new webbrowserdocumentcompletedeventhandler(handlerequest); firststep(); } } }
as said via comment, approach populating textboxes not orthodox and, actually, not working on computer. usual proceeding relying on setattribute
function. code become:
casenumber.setattribute("value", "12283"); casedate.setattribute("value", "03-10");
if , use inputtag.invokemember("click")
, form submitted (at least, no popup appears , browser redirected new page).
Comments
Post a Comment