Function Reference

_IEFormElementSetValue

指定されたフォーム要素の値を設定します。

#include <IE.au3>
_IEFormElementSetValue ( ByRef $o_object, $s_newvalue [, $f_fireEvent = 1] )

 

パラメータ

$o_object InternetExplorer.Applicationのオブジェクト変数、フォーム要素オブジェクト
$s_newvalue フォーム要素に設定される新しい値
$f_fireEvent [オプション]値設定後に変更(OnChange)、クリック(OnClick)のイベント発行をおこなうかどうかを指定します
0 = 値設定後、OnChange、OnClickイベントの発行をおこないません
1 = (デフォルト) 値設定後、OnChange、OnClickイベントの発行をおこないます

 

返し値

成功: 1を返します
失敗: 0を返し@ERRORを設定します
@Error: 0 ($_IEStatus_Success) = 正常終了
3 ($_IEStatus_InvalidDataType) = 無効なデータ型
4 ($_IEStatus_InvalidObjectType) = 無効なオブジェクト型
@Extended: 無効なパラメータの番号が格納されています

 

注意

全フォーム要素がvalueを持ちますが、テキスト指向要素のみが明示的な形でvalue属性を使用しています(type text、textarea、hidden、passwordとfile)。他のフォーム要素のvalueはユーザーインターフェイスに何が表示されるかについては影響を与えませんが、選択・アクティブ化時に要素から返される値には影響をあたえます。

さらに詳しい情報については_IEFormElementOptionSelect、_IEFormElementCheckboxSelect、_IEFormElementRadioSelect、_IEFormImageClickを参照

ノート: INPUT TYPE=FILEの要素の値設定には_IEFormElementSetValueを使えません。 ブラウザのセキュリティ制限がこの要素のスクリプト処理を妨害します。回避策については、以下の例を参照。

 

関連

_IEFormElementGetValue, _IEFormElementGetCollection, _IEFormElementGetObjByName, _IEFormElementOptionSelect, _IEFormElementCheckBoxSelect, _IEFormElementRadioSelect

 


; *******************************************************
; 例 1 - フォームのサンプルをブラウザで開き、テキストフォームに値を設定
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("form")
$oForm = _IEFormGetObjByName ($oIE, "ExampleForm")
$oText = _IEFormElementGetObjByName ($oForm, "textExample")
_IEFormElementSetValue ($oText, "Hey! This works!")

; *******************************************************
; 例 2 - 特定のフォーム要素への山陽を取得して値を設定
;              今回はGoogle検索エンジンにクエリをサブミット
; *******************************************************
;
#include <IE.au3>
$oIE = _IECreate ("http://www.google.com")
$oForm = _IEFormGetObjByName ($oIE, "f")
$oQuery = _IEFormElementGetObjByName ($oForm, "q")
_IEFormElementSetValue ($oQuery, "AutoIt IE.au3")
_IEFormSubmit ($oForm)

; *******************************************************
; 例 3 - Hotmailにログイン
; *******************************************************
;
#include <IE.au3>
; ブラウザウィンドウを作成してhotmailに移動
$oIE = _IECreate ("http://www.hotmail.com")

; ログインフォームとユーザー名、パスワードとサインインフィールドのポインタを取得。
$o_form = _IEFormGetObjByName ($oIE, "f1")
$o_login = _IEFormElementGetObjByName ($o_form, "login")
$o_password = _IEFormElementGetObjByName ($o_form, "passwd")
$o_signin = _IEFormElementGetObjByName ($o_form, "SI")

$username = "your username here"
$password = "your password here"

; フィールド値を設定、フォームをサブミット
_IEFormElementSetValue ($o_login, $username)
_IEFormElementSetValue ($o_password, $password)
_IEAction ($o_signin, "click")

; *******************************************************
; 例 4 - INPUT TYPE=FILE要素に値を設定
;               (セキュリティ制限が_IEFormElementSetValueの使用を妨害)
; *******************************************************
;
#include <IE.au3>

$oIE = _IE_Example("form")
$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

; フィールドに入力フォーカスをあわせ、テキスト文字列を送信
_IEAction($oInputFile, "focus")
Send("C:\myfile.txt")

; *******************************************************
; 例 5 - INPUT TYPE=FILE要素に値を設定
;               ウィンドウが非表示なこと以外は先の例と同じ
;               (セキュリティ制限が_IEFormElementSetValueの使用を妨害)
; *******************************************************
;
#include <IE.au3>

$oIE = _IE_Example("form")

; 非表示ウィンドウへテキストを送信するデモのためにブラウザウィンドウを非表示にする
_IEAction($oIE, "invisible")

$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

; フィールドに入力フォーカスをあわせ、テキスト文字列を送信
_IEAction($oInputFile, "focus")
$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "C:\myfile.txt")

MsgBox(0, "Success", "Value set to C:\myfile.txt")
_IEAction($oIE, "visible")