Einzelnen Beitrag anzeigen

gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#25

AW: Webbrowser OleObject - Felder füllen

  Alt 10. Apr 2013, 14:02
Hi

Also beim Einloggen gehen alle Felder und Buttons.
Delphi-Quellcode:
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin

if URL= 'http://www1.sunrise.ch/SMS-Sender-cbBpfAqFI.RUoAAAEwinJTNyCu-Sunrise-Residential-Site-WFS-de_CH-CHF.htmlthen begin
repeat;
Application.ProcessMessages;
Sleep(1);
until WebBrowser1.ReadyState=4;

webbrowser1.oleobject.document.forms.item(1).elements.item('LoginForm_Login').value := memo2.Lines[2];

if webbrowser1.oleobject.document.forms.item(1).elements.item('LoginForm_Login').value =memo2.Lines[2] then begin

webbrowser1.oleobject.document.forms.item(1).elements.item('LoginForm_Password').value := memo2.Lines[3] ;
//webbrowser1.oleobject.document.forms.item(1).submit;
end;
//Server1 ENDE
end;

Nach dem Einloggen geht KEIN Feld. Respektive findet kein Feld mehr...

Delphi-Quellcode:
function WBFillForm(wb: TWebBrowser; sFieldName: string; sValue: string): Boolean;
var
   i, j: Integer;
   FormItem: Variant;
begin
   Result := False;
   //no form on document
   if wb.OleObject.Document.all.tags('FORM').Length = 0 then begin
     Exit;
   end;
   //count forms on document
   for I := 0 to wb.OleObject.Document.forms.Length - 1 do begin
     FormItem := wb.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 AnsiUpperCase(FormItem.Item(j).Name) = AnsiUpperCase(sFieldName) then begin
           FormItem.Item(j).Value := sValue;
           Result := True;
         end;
       except
         Exit;
       end;
     end;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Application.ProcessMessages;
   while webbrowser1.Busy do Application.ProcessMessages;
   while webbrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages;
   if not WBFillForm(webbrowser1,'message',Memo1.Text) then begin
     ShowMessage('Das Textfeld message wurde nicht gefunden.');
   end;
      if not WBFillForm(webbrowser1,'recipient',combobox1.Items[combobox1.ItemIndex]+edit3.Text) then begin
     ShowMessage('Das Textfeld recipient wurde nicht gefunden.');
   end;

   Application.ProcessMessages;
   while webbrowser1.Busy do Application.ProcessMessages;
   while webbrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages;
end;
Robert
  Mit Zitat antworten Zitat