- Сообщения
- 7,790
- Репутация
- 2,322
Обнаружил ошибку в функции _IEFormElementOptionSelect(). Если использовать несуществующие значения $s_string, то, при использовании опций $s_mode byValue или byText, функция возвращает $_IEStatus_Success. То же самое, если при byIndex использовать строку.
Пример:
1.html:
По идее, должно быть примерно так:
Пример:
Код:
#include <IE.au3>
_IEErrorHandlerRegister('_Error_IE')
Dim $aPIN[5][2] = [[4],['Nothing', 'byValue'],['Nothing', 'byText'],[25, 'byIndex'],['Nothing', 'byIndex']]
;этих значений не существует
$sUrl = @ScriptDir & '\1.html'
$oIE = _IECreate($sUrl)
If @error Then Exit 13
For $j = 1 To 1
$oForm = _IEGetObjByName($oIE, 'fPIN')
If @error Then ExitLoop
$oSelect = _IEFormElementGetObjByName($oForm, 'pinnum')
If @error Then ExitLoop
ConsoleWrite('Все реальные значения:' & @LF)
$oOption = _IETagNameGetCollection($oSelect, 'option')
If @error Or Not @extended Then ExitLoop
For $i = 0 To @extended - 1
ConsoleWrite('Value = ' & $oOption.item($i).value & ', Index = ' & $i & ', Text = ' & $oOption.item($i).innertext & @LF)
Next
ConsoleWrite('Выбираем несуществующие значения:' & @LF)
For $i = 1 To $aPIN[0][0]
_IEFormElementOptionSelect($oSelect, $aPIN[$i][0], 1, $aPIN[$i][1])
ConsoleWrite('Select: ' & $aPIN[$i][0] & '; mode: ' & $aPIN[$i][1] & @TAB & 'Error = ' & @error & @LF)
Next
Next
;_IEQuit($oIE)
Func _Error_IE()
ConsoleWrite('ERROR IE' & @LF)
EndFunc ;==>_Error_IE
1.html:
Код:
<HEAD><TITLE>Тест функции _IEFormElementOptionSelect</TITLE>
<META content="text/html; charset=windows-1251" http-equiv=content-type></HEAD>
<BODY>
<TABLE border=0 cellSpacing=0 cellPadding=0 height=230>
<TBODY>
<TR>
<TD height=230 background=/vpnkeylocal/top-login-l.png width=52></TD>
<TD height=230 background=/vpnkeylocal/top-login-bg.gif width=230><FONT color=green size=5 face=Arial><B>VPNKey-TLS</B></FONT></TD>
<FORM method=post name=fPIN action="">
<TD height=230 background=/vpnkeylocal/top-login-fon.png width=483 align=middle><FONT color=white size=3 face=Arial><B>Учетная запись:</B></FONT>
<SELECT name=pinnum><OPTION selected value=0 ?SELECTED?>-Выберите запись-</OPTION><OPTION value=1>PIN 1</OPTION><OPTION value=2>PIN 2</OPTION><OPTION value=3>PIN 3</OPTION><OPTION value=4>PIN 4</OPTION><OPTION value=5>PIN 5</OPTION></SELECT>
<FONT color=white size=3 face=Arial><B>Код доступа:</B></FONT>
<INPUT value="" type=password name=pin>
<INPUT value=W_LOGIN_FUNC_ID type=hidden name=id>
<FONT color=white size=1 face=Arial>
</FONT>
<INPUT class=butSt src="/vpnkeylocal/h-enter.gif" type=image name=ButN></TD></FORM>
<TD height=230 background=/vpnkeylocal/top-login-r.png width=52></TD></TR></TBODY></TABLE></BODY>
Код:
Func _IEFormElementOptionSelectEx(ByRef $o_object, $s_string, $f_select = 1, $s_mode = "byValue", $f_fireEvent = 1)
If Not IsObj($o_object) Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidDataType")
Return SetError($_IEStatus_InvalidDataType, 1, 0)
EndIf
;
If Not __IEIsObjType($o_object, "formselectelement") Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidObjectType")
Return SetError($_IEStatus_InvalidObjectType, 1, 0)
EndIf
;
Local $oItems = $o_object.options, $iNumItems = $o_object.options.length, $f_isMultiple = $o_object.multiple
Switch $s_mode
Case "byValue"
For $oItem In $oItems
If $oItem.value = $s_string Then
Switch $f_select
Case -1
Return SetError($_IEStatus_Success, 0, $oItem.selected)
Case 0
If Not $f_isMultiple Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", _
"$f_select=0 only valid for type=select multiple")
SetError($_IEStatus_InvalidValue, 3)
EndIf
If $oItem.selected Then
$oItem.selected = False
If $f_fireEvent Then
$o_object.fireEvent("onChange")
$o_object.fireEvent("OnClick")
EndIf
EndIf
Return SetError($_IEStatus_Success, 0, 1)
Case 1
If Not $oItem.selected Then
$oItem.selected = True
If $f_fireEvent Then
$o_object.fireEvent("onChange")
$o_object.fireEvent("OnClick")
EndIf
EndIf
Return SetError($_IEStatus_Success, 0, 1)
Case Else
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value")
Return SetError($_IEStatus_InvalidValue, 3, 0)
EndSwitch
__IEErrorNotify("Warning", "_IEFormElementOptionSelect", "$_IEStatus_NoMatch", "Value not matched")
Return SetError($_IEStatus_NoMatch, 2, 0)
EndIf
Next
;Добавлено
__IEErrorNotify("Warning", "_IEFormElementOptionSelect", "$_IEStatus_NoMatch", "Value '" & $s_string & "' not matched")
Return SetError($_IEStatus_NoMatch, 2, 0)
;----------
Case "byText"
For $oItem In $oItems
If String($oItem.text) = $s_string Then
Switch $f_select
Case -1
Return SetError($_IEStatus_Success, 0, $oItem.selected)
Case 0
If Not $f_isMultiple Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", _
"$f_select=0 only valid for type=select multiple")
SetError($_IEStatus_InvalidValue, 3)
EndIf
If $oItem.selected Then
$oItem.selected = False
If $f_fireEvent Then
$o_object.fireEvent("onChange")
$o_object.fireEvent("OnClick")
EndIf
EndIf
Return SetError($_IEStatus_Success, 0, 1)
Case 1
If Not $oItem.selected Then
$oItem.selected = True
If $f_fireEvent Then
$o_object.fireEvent("onChange")
$o_object.fireEvent("OnClick")
EndIf
EndIf
Return SetError($_IEStatus_Success, 0, 1)
Case Else
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value")
Return SetError($_IEStatus_InvalidValue, 3, 0)
EndSwitch
__IEErrorNotify("Warning", "_IEFormElementOptionSelect", "$_IEStatus_NoMatch", "Text not matched")
Return SetError($_IEStatus_NoMatch, 2, 0)
EndIf
Next
__IEErrorNotify("Warning", "_IEFormElementOptionSelect", "$_IEStatus_NoMatch", "Text '" & $s_string & "' not matched")
Return SetError($_IEStatus_NoMatch, 2, 0)
Case "byIndex"
;Добавлено
If IsString($s_string) Then
If Not StringIsDigit($s_string) Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid index value '" & $s_string & "'")
Return SetError($_IEStatus_InvalidValue, 2, 0)
EndIf
EndIf
;----------
Local $i_index = Number($s_string)
If $i_index < 0 Or $i_index >= $iNumItems Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid index value, " & $i_index)
Return SetError($_IEStatus_InvalidValue, 2, 0)
EndIf
$oItem = $oItems.item($i_index)
Switch $f_select
Case -1
Return SetError($_IEStatus_Success, 0, $oItems.item($i_index).selected)
Case 0
If Not $f_isMultiple Then
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", _
"$f_select=0 only valid for type=select multiple")
SetError($_IEStatus_InvalidValue, 3)
EndIf
If $oItem.selected Then
$oItems.item($i_index).selected = False
If $f_fireEvent Then
$o_object.fireEvent("onChange")
$o_object.fireEvent("OnClick")
EndIf
EndIf
Return SetError($_IEStatus_Success, 0, 1)
Case 1
If Not $oItem.selected Then
$oItems.item($i_index).selected = True
If $f_fireEvent Then
$o_object.fireEvent("onChange")
$o_object.fireEvent("OnClick")
EndIf
EndIf
Return SetError($_IEStatus_Success, 0, 1)
Case Else
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid $f_select value")
Return SetError($_IEStatus_InvalidValue, 3, 0)
EndSwitch
Case Else
__IEErrorNotify("Error", "_IEFormElementOptionSelect", "$_IEStatus_InvalidValue", "Invalid Mode")
Return SetError($_IEStatus_InvalidValue, 4, 0)
EndSwitch
EndFunc ;==>_IEFormElementOptionSelectEx