質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
VBScript

VBScript(Visual Basic Scripting Edition)はMicrosftが開発したスクリプト言語であり、Visual Basicのサブセットです。

Q&A

1回答

19225閲覧

VBSを使用してのHP自動ログイン

退会済みユーザー

退会済みユーザー

総合スコア0

VBScript

VBScript(Visual Basic Scripting Edition)はMicrosftが開発したスクリプト言語であり、Visual Basicのサブセットです。

0グッド

0クリップ

投稿2018/03/28 04:14

前提・実現したいこと

VBSを使用して社内システムに自動ログインしたい

発生している問題・エラーメッセージ

IEが起動しHP表示されるがログインページが
新規ウィンドウで立ち上がりID,PASSが入力できない

該当のソースコード

作成したVBS

'頭で固定値をセットする 自分の番号をセットする。
strUID = "" 'ユーザー-ID、メールアドレスの人もいる
strPassword = "
" 'パスワードあまりスクリプトには保存したくないけど

'IEの起動

Dim objIE '変数を定義します。 Set objIE = WScript.CreateObject("InternetExplorer.Application") 'オブジェクト作成 objIE.Visible = True '可視、Trueで見えるようにします。

'処理したいページを表示します。
'ここでは、ログインページを直接呼びます
objIE.Navigate "http://*****************"

'ページの表示完了を待ちます。
While objIE.ReadyState <> 4 Or objIE.Busy = True '.ReadyState <> 4の間まわる。
WScript.Sleep 100 '0.1秒待つ 1000で1秒
Wend

'ユーザー-ID(name=u)にセットする。
Set objU = objIE.Document.getElementsByName("loginBTO.userId") '変数に一度セットする

If objU.Length = 0 Then '.Lengthで 取得したエレメントの数がわかります '終了処理/エラー処理 0の時は見つからなかったので Msgbox "ログイン失敗" WScript.Quit 'スクリプトを途中で抜ける End If objU(0).Value = strUID 'データをセットする Set objU = Nothing 'オブジェクト変数解放

'パスワード(name=p)にセットする。
objIE.Document.getElementsByName("loginBTO.password").Item(0).Value = strPassword 'セットする

'次へ ボタンを探して押す
'input type="submit" value=" ログイン "> を 探す

'INPUTのタグを集める .getElementsByTagName("INPUT")を使用 Set objINPUT = objIE.Document.getElementsByTagName("INPUT") 'ループで頭からテキストが 次へ を探す For n = 0 To objINPUT.Length - 1 '※ type="submitボタンなので、.InnerTextじゃなくて、.Valueです ※※注意 If Instr(objINPUT(n).Value,"次へ") > 0 Then '文字列の中から見つけたら objINPUT(n).Click '見つけたINPUTタグのオブジェクトをクリック Exit For End If Next Set objINPUT = Nothing 'オブジェクト変数解放

試したこと

補足情報(FW/ツールのバージョンなど)

HPソース

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> <meta http-equiv="content-script-type" content="text/javascript"> <meta http-equiv="content-style-type" content="text/css"> <title>"ログイン"</title> <script type="text/javascript" src="js/Common.js"></script> <link rel="stylesheet" href="css/Common.css" type="text/css"> <style type="text/css"> <!-- body { width: auto; }

td {
background-color: transparent;
}

input.button_width {
width: 10em;
}
-->
</style>

<script type="text/javascript"> <!-- submitFlag = false; var doublepressmsg = "WWG01001 ボタン及びリンクの二重押下は禁止されています。"; var doubleLoginmsg = "null"; function login() { document.loginForm.action = "login.do"; submitForm(document.loginForm); } function goPassChange() { document.loginForm.action = "goPassChange.do"; loginForm.submit(); } function doubleLogin() { // index.html から起動されなかった場合は、index.htmlに遷移。 // ブラウザバージョンチェックの実施およびメニューなどを消して起動するため。 var fromIndex = 'from_index'; var locationHref = "./"; if (window.name != fromIndex) { location.href = locationHref; return; } if (doubleLoginmsg != "null") { alert(doubleLoginmsg); } } //--> </script> </head> <body onload="doubleLogin()"> <table align="center" bgcolor="#000067" border="0" width=100%> <tr> <td align="center"> <img src="image/h_logotop1.jpg" alt="logo">
</td>
</tr> </table> <hr> <div align="center"> <!-- エラーメッセージ出力 --> </div> <form name="loginForm" method="post" action="/bba-web/login.do"> <INPUT type="hidden" name="screenBTO.eventId" value="1"> <table align="center" summary="login" frame="box" style="width: 800px " border="0"> <colgroup span="2" width="25%"> </colgroup> <tr> <td>&nbsp; </td> <td class="center">ユーザID </td> <td> <input type="text" name="loginBTO.userId" maxlength="50" size="20" value="" class=".login">
</td>
</tr> <tr> <td>&nbsp; </td> <td class="center">パスワード </td> <td> <input type="password" name="loginBTO.password" maxlength="50" size="20" value="" class=".login">
</td>
</tr> <tr> <td colspan="3">&nbsp; </td> </tr> <tr> <td> </td> <td class="right"> <input type="button" name="button1" value="ログイン" onclick="login()" onkeypress="" id="loginButton" class="button_width">
</td> <td> <input type="button" name="button2" value="パスワード変更" onclick="goPassChange();" onkeypress="" id="changeButton" class="button_width"> </td>
</tr> </table> <br> <table align="center" summary="notice" border="0"> <tr> <th class="center">お知らせ </th> </tr> <tr> <td align="center">
</FONT> <BR> </td>
</tr> </table> </form> <script type="text/javascript" language="JavaScript"> <!-- var focusControl = document.forms["loginForm"].elements["loginBTO.userId"];

if (focusControl != null && focusControl.type != "hidden" && !focusControl.disabled && focusControl.style.display != "none") {
focusControl.focus();
}
// -->
</script>

</body> </html>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

https://teratail.com/questions/156884
ここらへんがさんこーになりますねー

投稿2019/03/18 01:50

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問