ウェブページ (www.soccerproject.com) にログインしようとしています (いくつかの日常的なタスクを実行するため) ID を開始します。ボタンの onClick メソッドにバインドされた JavaScript を実行しようとしましたが、うまくいきませんでした。ここに私のコードを示します。
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.soccerproject.com/spnewl_index.php');
end;
procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var ii:integer ;
begin
if (WebBrowser1.LocationURL='http://www.soccerproject.com/spnewl_index.php') and (i<4) then inc(i);
if i=4 then begin
WebBrowser1.OleObject.Document.getElementById('login').setAttribute('value', Edit1.Text);
WebBrowser1.OleObject.Document.getElementById('password').setAttribute('value', Edit2.Text);
wait(200);
WebBrowser1.OleObject.Document.forms[0].submit();
WebBrowser1.Navigate('http://www.soccerproject.com/#');
end;
end;
私が 4 にカウントする理由は、webBrowser が Web サイトを完全にロードして表示する (テキストを入力できるようにする) 必要があるためです。また、wait() 関数は単純に 200 ミリ秒待機します (念のため)。前もって感謝します