0

次のように、Java コードから IE を介して Web ページを開きます。

Runtime.getRuntime().exec(url).

私の Web ページには、ユーザー名とパスワード (すべてのユーザーでほぼ同じユーザーとパスワード) を含む認証画面が表示されます。

さらに、ハードコードされたユーザー名とパスワードを自動的に入力する Java スクリプトを作成しました。フォーカスが自分の Web ページにあるときに手動で実行すると、正常に動作します。

上記のコマンドでスクリプトを実行する可能性はありますか? ページを開いて、ユーザーとパスワードが入力されるようにしたいだけです...

ありがとう!

4

2 に答える 2

3

Firstly, your method of launching the browser is rather flaky. What you're currently doing is running the URL as if it were a command, i.e. the name of a process to run. This is similar to typing it at a command prompt or the Windows Run... dialog. Fortunately in this case, Windows interprets an attempt to execute an HTTP URL by launching IE with that URL, but that's not likely to be consistent in other environments. A better approach would be to use Desktop.browse, which specifically launches the URL in the default browser.

As to your question itself, it's very unlikely this is possible. You're spawning a new (IE) process, which is completely separate from your Java process. Without some form of inter-process communication, Java won't be able to send commands to IE on the fly. The only possible way this might work is by passing arguments to the command that are interpreted by the new process. To my knowledge however there are no command-line arguments that will cause IE to run an arbitrary piece of JS once a page is loaded.

于 2013-10-15T15:04:34.837 に答える
-1

To run code when the page loads. Put it in an onload function.

window.onload = function(){
  // your javascript code here
}
于 2013-10-15T15:02:42.933 に答える