2015-10-23 10:16:42 (Fri);
WEB画面(IE)を自動で操作したい!
負荷試験や自動処理など、一定間隔でボタンを自動押下させたい
というときの WScrit サンプル。
停止する場合は、タスクマネージャーのプロセスから
「wscript.exe」を終了させる。
以下のサンプルは、
1.ボタンを押下
2.OK/キャンセルダイアログでOKを押下
という処理を書いたもの。
ボタンのオブジェクト名やダイアログは環境によって変えてください。
auto_click.vbs
'----------------------------------------------
' Web画面自動クリックScript
'----------------------------------------------
Option Explicit
timer
WScript.Echo "END"
'指定間隔で実行(1000=1秒)
Sub timer()
Dim cnt
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
'1000回実施
Do While cnt < 1000
cnt = cnt + 1
WshShell.popup "実行回数は" & cnt & "回目です。", 3
'処理実行。その後150秒待つ
auto_click
WScript.Sleep 150000
Loop
End Sub
'起動中のIEを取得し特定の処理を実行
Sub auto_click()
Dim OBJ_FSO
Dim OBJ_Browser
Dim STR_ProgramName
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set OBJ_FSO = CreateObject("Scripting.FileSystemObject")
For Each OBJ_Browser In CreateObject("Shell.Application").[[Windows]]
STR_ProgramName = OBJ_FSO.GetFileName(OBJ_Browser.FullName)
'IEの時に処理開始
If LCase(STR_ProgramName) = "iexplore.exe" Then
'実行ボタンを押下(btnGという名前と仮定)
OBJ_Browser.Document.getElementsByName("btnG")(0).Click
WScript.sleep 5000
'処理確認ダイアログを押す
WshShell.AppActivate "Microsoft Internet Explorer"
WshShell.SendKeys("{ENTER}")
'押せなかった時のための保険
WScript.sleep 2000
WshShell.SendKeys("{ENTER}")
Exit for
End If
Next
End Sub
最終更新:2015年10月23日 10:16