Delphi7 WebForm Doldurma ve Submit etme

Web sayfalarındaki Form doldurmak  ve istediğiniz formu (aynı anda 2 veya daha fazlası varsa) submit etmek için kullanacağınız güzel bir kod.

Kod Kullanmaya başlamadan önce eklenecek satırlar

Uses MSHTML,... ;
Var   iall : IHTMLElement;

function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
i, j: Integer;
FormItem: Variant;
begin
Result := False;

for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
begin
FormItem := WebBrowser.OleObject.Document.forms.Item(I);
for j := 0 to FormItem.Length - 1 do
begin

 

try
//when the fieldname is found, try to fill out
if FieldName='submit' then
if FormItem.Item(j).Name = 'submit' then
begin
FormItem.Item(j).click;
exit;
end;

if FormItem.Item(j).Name = FieldName then
begin
FormItem.Item(j).Value := Value;
Result := True;
end;
except
Exit;
end;
end;
end;
end;

 

function GetFormByNumber(document: IHTMLDocument2;
formNumber: integer): IHTMLFormElement;
var
forms: IHTMLElementCollection;
begin
forms := document.Forms as IHTMLElementCollection;
if formNumber < forms.Length then
result := forms.Item(formNumber,'') as IHTMLFormElement
else
result := nil;
end;


procedure TForm1.Button2Click(Sender: TObject);
var
theForm: IHTMLFormElement;
document: IHTMLDocument2;
begin         
fillform(WebBrowser1,'hesapno','00'+ADODataSet1HESAPNO.Text);
fillform(WebBrowser1,'submit','');

document := WebBrowser1.Document as IHTMLDocument2;
theForm := GetFormByNumber(document, 0);
TheForm.submit;    
end;

 

BeÄŸendin mi? PaylaÅŸ!