1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
| function LoginGMX(AKennung, APasswort: string): Boolean; const IEFields: array[1..4] of string = ('INPUT', 'text', 'INPUT', 'password'); var ShellWindow: IShellWindows; WB: IWebbrowser2; spDisp: IDispatch; IDoc1: IHTMLDocument2; Document: Variant; k, m: Integer; ovElements: OleVariant; i: Integer; IEFieldsCounter: Integer; begin ShellWindow := CoShellWindows.Create; // get the running instance of Internet Explorer for k := 0 to ShellWindow.Count do begin spDisp := ShellWindow.Item(k); if spDisp = nil then Continue; // QueryInterface determines if an interface can be used with an object spDisp.QueryInterface(iWebBrowser2, WB); if WB <> nil then begin WB.Document.QueryInterface(IHTMLDocument2, iDoc1); if iDoc1 <> nil then begin WB := ShellWindow.Item(k) as IWebbrowser2; Document := WB.Document; // if GMX page... if Pos('GMX - Homepage', Document.Title) <> 0 then // count forms on document and iterate through its forms IEFieldsCounter := 0; for m := 0 to Document.forms.Length - 1 do begin ovElements := Document.forms.Item(m).elements;
// iterate through elements for i := ovElements.Length - 1 downto 0 do begin try // if input fields found, try to fill them out if (ovElements.item(i).tagName = IEFields[1]) and (ovElements.item(i).type = IEFields[2]) then begin ovElements.item(i).Value := AKennung; inc(IEFieldsCounter); end;
if (ovElements.item(i).tagName = IEFields[3]) and (ovElements.item(i).type = IEFields[4]) then begin ovElements.item(i).Value := APasswort; inc(IEFieldsCounter); end; except // failed... end; end; { for i...} end; { for m } end; { idoc <> nil } end; { wb <> nil } // if the fields are filled in, submit. if IEFieldsCounter = 3 then ExecuteScript(iDoc1, 'document.login.submit()', 'JavaScript'); end; { for k } end;
procedure TForm1.Button1Click(Sender: TObject); begin LoginGMX('username@gmx.net', 'pswd'); end; |