000
21.11.2004, 15:54 Uhr
~Peter
Gast
|
Hallo, ich mocht ein Programm schreiben, dass sich automatisch per JavaScript an einer Website anmeldet. Momentan sieht das folgendermaßen aus:
Code: |
procedure TForm1.Button1Click(Sender: TObject); var IDoc1: IHTMLDocument2; Web: ShDocVW.IWebBrowser2; begin while Webbrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages; Webbrowser1.Document.QueryInterface(IHTMLDocument2, iDoc1); Web := WebBrowser1.ControlInterface; FillIn(Web, iDoc1, Webbrowser1.Document); end;
function TForm1.ExecuteScript(doc: IHTMLDocument2; script: string; language: string): Boolean; var win: IHTMLWindow2; Olelanguage: Olevariant; begin result:=false; if doc <> nil then begin try win := doc.parentWindow; if win <> nil then begin try Olelanguage := language; win.ExecScript(script, Olelanguage); finally win := nil; result:=true; end; end; finally doc := nil; end; end; end;
procedure TForm1.FillIn(WB: ShDocVW.IWebbrowser2; IDoc1: IHTMLDocument2; Document: Variant); const IEFields: array[1..4] of string = ('INPUT', 'text', 'INPUT', 'password'); var IEFieldsCounter: Integer; i: Integer; m: Integer; ovElements: OleVariant; begin if Pos('Taenaria', Document.Title) <> 0 then while WB.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages; // 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 := 'ComJackBane'; Inc(IEFieldsCounter); end; if (ovElements.item(i).tagName = IEFields[3]) and (ovElements.item(i).type = IEFields[4]) then begin ovElements.item(i).Value := 'Voodoo'; Inc(IEFieldsCounter); end; except // failed... end; end; { for i...} end; { for m } // if the fields are filled in, submit. if IEFieldsCounter = 2 then ExecuteScript(iDoc1, 'document.login.submit()', 'JavaScript'); end;
procedure TForm1.Button2Click(Sender: TObject); begin webBrowser1.Navigate('http://www.tdzk.net'); end;
|
Nun kommt aber immer die JavaScript-Fehlermeldung des Browsers: In dem Script auf dieser Seite ist ein Fehler aufgetreten. Zeile: 1 Zeichen: 1 Fehler: 'document.login' ist Null oder kein Objekt Code: 0 ...
Woran liegt das? |