24th
Авг

Как в WebBrowser выбрать из списка и нажать на кнопку?

Posted by Chas under Пост-обзор

Posted by Chas under Пост-обзор

zlodey:

Нажатие на кнопку:
код:

procedure PSpisokClick;
var HtmlDocument : IHtmlDocument2;
   i : integer;
   HtmlCollection : IHtmlElementCollection;
   HtmlElement : IHtmlElement;
   spisok : string;
begin
   HtmlDocument := BrowserMain.Document as IHtmlDocument2;
   HtmlCollection := HtmlDocument.All;
   for i := 0 to HtmlCollection.length – 1 do
   begin
     if stop = 1 then Exit;
     HtmlElement := HtmlCollection.Item(i, 1) as IHtmlElement;
     spisok := HtmlElement.InnerText;
     Trim(spisok);
     if spisok = ‘список’ then
     begin
       HtmlElement.click;
       Exit;
     end;
   end;
end;

выбор из открывающегося списка:
код:

procedure SetFieldValue(theForm: IHTMLFormElement;
const fieldName, newValue: string; const instance: integer);
var
   field: IHTMLElement;
   inputField: IHTMLInputElement;
   selectField: IHTMLSelectElement;
   textField: IHTMLTextAreaElement;
begin
   field := theForm.Item(fieldName,instance) as IHTMLElement;
   if Assigned(field) then
   begin
     if field.tagName = ‘INPUT’ then
     begin
       inputField := field as IHTMLInputElement;
       if (inputField.type_ ‘radio’) and (inputField.type_ ‘checkbox’)
       then inputField.value := newValue
       else inputField.checked := (newValue = ‘checked’);
     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;

вызов процедуры:
код:

theForm := GetFormByNumber(BrowserMain.Documen t as IHTMLDocument2,0);
SetFieldValue(theForm,’type’,переменная);

Тема на форуме

Похожие статьи

Теги: |