↑  ←  Описание функции


_IEFormElementSetValue

Set the value of a specified Form Element.

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

Параметры

$o_object Переменная объекта InternetExplorer.Application, Form Element object
$s_newvalue The new value to be set into the Form Element
$f_fireEvent [необязательный] specifies whether to fire an OnChange event after changing value
0 = Do not fire OnChange or OnClick event after setting value
1 = (по умолчанию) fire OnChange and OnClick event after setting value

Возвращаемое значение

Успех:Возвращает 1
Ошибка:Возвращает 0 и устанавливает @error
@error:0 ($_IEStatus_Success) = Нет ошибок
3 ($_IEStatus_InvalidDataType) = Неверный тип данных
4 ($_IEStatus_InvalidObjectType) = Неверный тип объекта
@extended:Содержит номер неверного параметра

Примечания

While all Form Elements have a value, only text oriented elements use their value attribute in an obvious fashion (type text, textarea, hidden, password and file). The value of other form elements does not affect what is displayed in the user interface, but rather the value that is returned by the element when it is selected or activated.

See _IEFormElementOptionSelect, _IEFormElementCheckboxSelect, _IEFormElementRadioSelect and _IEFormImageClick for more information.

Note: You cannot use _IEFormElementSetValue to set the value of an INPUT TYPE=FILE element. Browser security restrictions prevent this element from being scripted. See the example below for a workaround.

См. также

_IEFormElementGetValue, _IEFormElementGetCollection, _IEFormElementGetObjByName, _IEFormElementOptionSelect, _IEFormElementCheckboxSelect, _IEFormElementRadioSelect

Пример

; *******************************************************
; Пример 1 - Open a browser with the form example, set the value of a text form element
; *******************************************************

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oText = _IEFormElementGetObjByName($oForm, "textExample")
_IEFormElementSetValue($oText, "Hey! This works!")

; *******************************************************
; Пример 2 - Get a reference to a specific form element and set its value.
;               In this case, submit a query to the Google search engine
; *******************************************************

#include <IE.au3>

$oIE = _IECreate("http://www.google.com")
$oForm = _IEFormGetObjByName($oIE, "f")
Local $oQuery = _IEFormElementGetObjByName($oForm, "q")
_IEFormElementSetValue($oQuery, "AutoIt IE.au3")
_IEFormSubmit($oForm)

; *******************************************************
; Пример 3 - Set the value of an INPUT TYPE=TEXT element using Send()
; *******************************************************

#include <IE.au3>

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

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")

; Select existing content so it will be overwritten.
_IEAction($oInputFile, "selectall")

Send("This works")

; *******************************************************
; Пример 4 - Set the value of an INPUT TYPE=TEXT element on an invisible
;               window using ControlSend()
; *******************************************************
;
#include <IE.au3>

$oIE = _IE_Example("form")

; Hide the browser window to demonstrate sending text to invisible window
_IEAction($oIE, "invisible")

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

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")

; Select existing content so it will be overwritten.
_IEAction($oInputFile, "selectall")

; Get a handle to the IE window.
Local $hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "This works")

MsgBox(4096, "Success", "Value set to 'This works'")
_IEAction($oIE, "visible")