var Form : ihtmlformelement ; D:ihtmldocument2 ; begin with WebBrowser1 do begin D : = Document as IHTMLDocument2; Form : = d.forms.item (' Form1 ', 0) as ihtmlformelement; Form1 the table sole name //title as the text box in the form (Form.item (' title ', 0) as IHTMLElement). SetAttribute (' value ', S_ title,0); (Form.item (' content ', 0) as IHTMLElement). SetAttribute (' value ', edit1.text,0); (Form.item (' Add ', 0) as IHTMLElement). Click;//add is the button name end;
Get and set input form values in Delphi's WebBrowser
var i:integer; Myole:olevariant;begin myole: = wb1. Document; For I: = 0 to Myole.all.length-1 does begin if Myole.all.item (i). TagName = ' INPUT ' then begin Mmo1. Lines.add (Myole.all.item (i). name); Mmo1. Lines.add (Myole.all.item (i). value); End; End;end;
Webbrowser1.gohome; To the browser default home page Webbrowser1.refresh; Refresh Webbrowser1.goback; Back Webbrowser1.goforward; Forward WebBrowser1.Navigate (' ... '); Opens the specified page webbrowser1.navigate (' About:blank '); Open empty page--------------------------------------------------------------------------------//Open empty page and write to ... WebBrowser1.Navigate (' about:
Log in on your own initiative
Input Varo:olevariant;begino for single frames: = WebBrowser.OleObject.document.all.item (' Loginuserid ', 0); Locate the login username input box O.value: = ' TEST '; O: = WebBrowser.oleobject.document.all.item (' Loginpassword ', 0); Locate the input box for login password O.value: = ' TEST ' WebBrowser.oleobject.document.Forms.Item (0, 0). Submit; First form submission {o: =webbrowser.oleobject.document.all.item (' Login ', 0); Or submit an O with the specified form name. Click; Click Action, other objects can also be the same operation}end, multiple frames input, FrameIndex for the frame ordinal varo:olevariant;begin//find the login username input box o: = WebBrowser.oleobject.document.documentelement.document.frames.item (FrameIndex). Document.All.Item (' Loginuserid ' , 0); O.value: = ' TEST ';//Find the input box for login password o: = WebBrowser.oleobject.document.documentelement.document.frames.item ( Framindex). Document.All.Item (' Loginpassword ', 0); O.value: = ' TEST '// The first form submits a WebBrowser.oleobject.document.documentelement.document.frames.item (Framindex). Document. Forms.item (0, 0). Submit; {//or submit with the specified form name o: =webbrowser.oleobject.document.documentelement.document.frames.item (Framindex).. Document.All.Item (' Login ', 0); O. Click; Click on the operation, other objects can also be the same operation}end;
Delphi WebBrowser Regular Usage Demo sample