Set the value of a specified form element.
#include <IE.au3>
_IEFormElementOptionSelect ( ByRef $o_object, $s_string [, $f_select = 1 [, $s_mode = "byValue" [, $f_fireEvent = 1]]] )
Parameters
$o_object | Form Element Object of type "Select Option" |
$s_string | Value used to match element - treatment based on $s_mode |
$f_select | Optional: specifies whether element should be selected or deselected -1 = Return selected state 0 = Deselect the element 1 = (Default) Select the element |
$s_mode | Optional: specifies search mode byValue = (Default) value of the option you wish to select byText = text of the option you wish to select byIndex = 0-based index of option you wish to select |
$f_fireEvent | Optional: specifies whether to fire an OnChange event after changing value 0 = do not fire OnChange event after setting value 1 = (Default) fire OnChange event after setting value |
Return Value
Success: | If $f_select = -1, returns the current selected state, else returns 1 |
Failure: | Returns 0 and sets @ERROR |
@Error: | 0 ($_IEStatus_Success) = No Error |
3 ($_IEStatus_InvalidDataType) = Invalid Data Type | |
4 ($_IEStatus_InvalidObjectType) = Invalid Object Type | |
5 ($_IEStatus_InvalidValue) = Invalid Value | |
7 ($_IEStatus_NoMatch) = No Match | |
@Extended: | Contains invalid parameter number |
Remarks
The $f_fireEvent parameter is significant only if the form element has an onChange event associated with it.
Related
_IEFormElementCheckBoxSelect, _IEFormElementRadioSelect
Example
; *******************************************************
; Example 1 - Open a browser with the form example, get reference to form, get reference
; to select element, cycle 10 times selecting options byValue, byText and byIndex
; Note: You will likely need to scroll down on the page to see the changes
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("form")
$oForm = _IEFormGetObjByName ($oIE, "ExampleForm")
$oSelect = _IEFormElementGetObjByName ($oForm, "selectExample")
For $i = 1 To 10
_IEFormElementOptionSelect ($oSelect, "Freepage", 1, "byText")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, "midipage.html", 1, "byValue")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, 0, 1, "byIndex")
Sleep(1000)
Next
; *******************************************************
; Example 2 - Open a browser with the form example, get reference to form, get reference
; to select multiple element, cycle 5 times selecting and then deselecting
; options byValue, byText and byIndex.
; Note: You will likely need to scroll down on the page to see the changes
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("form")
$oForm = _IEFormGetObjByName ($oIE, "ExampleForm")
$oSelect = _IEFormElementGetObjByName ($oForm, "multipleSelectExample")
For $i = 1 To 5
_IEFormElementOptionSelect ($oSelect, "Carlos", 1, "byText")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, "Name2", 1, "byValue")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, 5, 1, "byIndex")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, "Carlos", 0, "byText")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, "Name2", 0, "byValue")
Sleep(1000)
_IEFormElementOptionSelect ($oSelect, 5, 0, "byIndex")
Sleep(1000)
Next
; *******************************************************
; Example 3 - Open a browser with the form example, get reference to form, get reference
; to select element, check to see if the option "Freepage" is selected and
; report result. Repeat for the option with index 0 and for the option
; with value of 'midipage.html'
; Note: You will likely need to scroll down on the page to see the changes
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("form")
$oForm = _IEFormGetObjByName ($oIE, "ExampleForm")
$oSelect = _IEFormElementGetObjByName ($oForm, "selectExample")
If _IEFormElementOptionSelect ($oSelect, "Freepage", -1, "byText") Then
MsgBox(0, "Option Selected", "Option Freepage is selected")
Else
MsgBox(0, "Option Selected", "Option Freepage is Not selected")
EndIf
If _IEFormElementOptionSelect ($oSelect, 0, -1, "byIndex") Then
MsgBox(0, "Option Selected", "The First (index 0) option is selected")
Else
MsgBox(0, "Option Selected", "The First (index 0) option is Not selected")
EndIf
If _IEFormElementOptionSelect ($oSelect, "midipage.html", -1, "byValue") Then
MsgBox(0, "Option Selected", "The option with value 'midipage.html' is selected")
Else
MsgBox(0, "Option Selected", "The option with value 'midipage.html' is NOT selected")
EndIf