我有以下 Delphi 代码来填写 TWebBrowser 上的表格:
procedure SetFieldValue(theForm: IHTMLFormElement; const fieldName: string; const newValue: string);
var
field: IHTMLElement;
inputField: IHTMLInputElement;
selectField: IHTMLSelectElement;
textField: IHTMLTextAreaElement;
begin
field := theForm.Item(fieldName, '') as IHTMLElement;
if Assigned(field) then
begin
if field.tagName = 'INPUT' then
begin
inputField := field as IHTMLInputElement;
// Make the change below to catch checks and radios.
if (inputField.type_ = 'checkbox') or (inputField.type_ = 'radio') then
begin
if newValue = 'Y' then
inputField.checked := True
else
inputField.checked := False;
end
else
inputField.value := newValue;
end
else if field.tagName = 'SELECT' then
begin
selectField := field as IHTMLSelectElement;
selectField.value := newValue;
end
else if field.tagName = 'TEXTAREA' then
begin
textField := field as IHTMLTextAreaElement;
textField.value := newValue;
end;
end;
end;
HTML 源代码类似于以下示例:
<select name="xosid">
<option value="" selected>-- choose one --</option>
<option value="first">This is one</option>
<option value="second">Another</option>
</select>
我想修改上述函数,以便能够在不知道值的情况下从下拉列表中选择“另一个”...
有什么建议么?
提前致谢,
佐尔特