Ich habe mal folgende Funktion zum Auswählen eines Items aus einer Liste geschrieben:
Delphi-Quellcode:
function WB_select_SelectItem(WB: TWebBrowser; SelectName, ItemName: string): boolean;
var
iForms, iFormItems, iSelectItems: Word;
FormItem: OleVariant;
begin
Result := False;
for iForms := 0 to WB.OleObject.Document.forms.Length - 1 do
begin
FormItem := WB.OleObject.Document.forms.Item(iForms);
for iFormItems := 0 to FormItem.Length - 1 do
begin
if (FormItem.Item(iFormItems).type = 'select-one') and
(FormItem.Item(iFormItems).Name = SelectName) then
begin
for iSelectItems := 0 to FormItem.Item(iFormItems).Options.Length - 1 do
begin
if SameText(FormItem.Item(iFormItems).Options.Item(iSelectItems).Text, ItemName) then
begin
FormItem.Item(iFormItems).SelectedIndex := iSelectItems;
Result := True;
Break;
end;
end;
end;
end;
end;
end;
Aufruf für obiges Beispiel würde so aussehen:
WB_select_SelectItem(Webbrowser1, 'top5','Tom Waits');