Hello.
i am using T WebBrowser and want to fill HTML web form fields and submit form. My code sample is:
function FillForm(WebBrowser: TWebBrowser; FieldName: string; Value: string): Boolean;
var
i, j: Integer;
FormItem: Variant;
begin
Result := False;
//no form on document
if WebBrowser.OleObject.Docum
ent.all.ta
gs('FORM')
.Length = 0 then
begin
Showmessage('nera formu');
Exit;
end;
//count forms on document
for I := 0 to WebBrowser.OleObject.Docum
ent.forms.
Length - 1 do
begin
FormItem := WebBrowser.OleObject.Docum
ent.forms.
Item(I);
for j := 0 to FormItem.Length - 1 do
begin
try
//when the fieldname is found, try to fill out
if FormItem.Item(j).Name = FieldName then
begin
FormItem.Item(j).Value := Value;
Result := True;
end;
except
ShowMessage('ajajai klaida');
Exit;
end;
end;
end;
end;
// Step Number 1
// loading page
procedure TfrmMain.Button1Click(Send
er: TObject);
begin
WebBrowser1.Navigate(edDes
t.Text);
end;
// Step Number 2
// filling and submiting form
procedure TfrmMain.Button2Click(Send
er: TObject);
const
fields: array[1..11] of string=('title', 'location', 'description', 'age', 'contact_email', 'first_name', 'last_name', 'user_phone', 'user_email', 'password', 'policy_accepted');
values: array[1..11] of string=('title geras cia yra',
'lokacija',
'Deskripcija', '18', 'exga@yahoo.com', 'Ixmamud', 'ehmeda', '348665954', 'Car@yahoo.com', '123456789', '1');
var
theForm: IHTMLFormElement;
document: IHTMLDocument2;
i: integer;
begin
// fill form fields
for i:=1 to Length(fields) do
begin
if FillForm(WebBrowser1, fields[i], values[i]) = False then
Showmessage ('Your Form could not be Filled !')
end;
// submit form
document := WebBrowser1.Document as IHTMLDocument2;
theForm := GetFormByNumber(document, 0);
TheForm.submit;
end;
end;
after submiting form i got page erorr: "This posting category does not support images.". But i did not post image so i don't know where error exists. Help please.
Start Free Trial