Jump to content

Recommended Posts

Posted

Is there a way to set focus on a specific form field so that simulated key strokes can be sent?

This example doesn't work, because the _IEFormElementSetValue function returns an error. I changed the url because I'm testing it on a localhost. Everything works except the send keystrokes.

$IE = _IECreate("http://example.com/index.php?menu=3") 
WinSetState("", "", @SW_MAXIMIZE)
Sleep(Random(1000, 1500, 1))
$oDiv = _IEGetObjById ($IE, "name")
_IEFormElementSetValue($oDiv, sendKeyStrokes($firstName))

#cs ----------------------------------------------------------------------------
    This is s simple function that takes a string as an argument and outputs
    key strokes.
#ce ----------------------------------------------------------------------------

Func sendKeyStrokes($sendString)
    $TempStringArr = StringSplit( $sendString, "" , 0)
    For $x = 1 to $TempStringArr[0] Step 1
        Sleep(Random(350, 1000, 1))
        Send($TempStringArr[$x])
    Next
EndFunc

I just need to find a way to set focus on the form field.

Posted

I just pulled and modified the function _IEFormElementSetValue in IE.au3

from:

Func _IEFormElementSetValue(ByRef $o_object, $s_newvalue, $f_fireEvent = 1)
    If Not IsObj($o_object) Then
        __IEErrorNotify("Error", "_IEFormElementSetValue", "$_IEStatus_InvalidDataType")
        SetError($_IEStatus_InvalidDataType, 1)
        Return 0
    EndIf
    ;
    If Not __IEIsObjType($o_object, "forminputelement") Then
        __IEErrorNotify("Error", "_IEFormElementSetValue", "$_IEStatus_InvalidObjectType")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    ;
    If String($o_object.type) = "file" Then
        __IEErrorNotify("Error", "_IEFormElementSetValue", "$_IEStatus_InvalidObjectType", "Browser securuty prevents SetValue of TYPE=FILE")
        SetError($_IEStatus_InvalidObjectType, 1)
        Return 0
    EndIf
    ;
    $o_object.value = $s_newvalue
    If $f_fireEvent Then
        $o_object.fireEvent("onchange")
        $o_object.fireEvent("onclick")
    EndIf
    SetError($_IEStatus_Success)
    Return 1
EndFunc   ;==>_IEFormElementSetValueoÝ÷ ÚÚºÚ"µÍ[ÈÒQQÜQ[[Y[Ù[Ù^TÝÚÙÊTY  ÌÍÛ×ÛØXÝ ÌÍÜ×Û]Ý[YK    ÌÍÙÙQ][HJBRYÝÓØ  ÌÍÛ×ÛØXÝ
H[BW×ÒQQÜÝYJ    ][ÝÑÜ][ÝË  ][Ý×ÒQQÜQ[[Y[Ù][YI][ÝË   ][ÝÉÌÍ×ÒQTÝ]×Ò[[Y]UI][ÝÊBBTÙ]Ü ÌÍ×ÒQTÝ]×Ò[[Y]UKJBBT]Q[YNÂRYÝ×ÒQRÓØJ   ÌÍÛ×ÛØXÝ ][ÝÙÜZ[][[Y[ ][ÝÊH[BW×ÒQQÜÝYJ  ][ÝÑÜ][ÝË  ][Ý×ÒQQÜQ[[Y[Ù][YI][ÝË   ][ÝÉÌÍ×ÒQTÝ]×Ò[[YØXÝI][ÝÊBBTÙ]Ü  ÌÍ×ÒQTÝ]×Ò[[YØXÝKJBBT]Q[YNÂRYÝ[Ê    ÌÍÛ×ÛØXÝJHH  ][ÝÙ[I][ÝÈ[BW×ÒQQÜÝYJ   ][ÝÑÜ][ÝË  ][Ý×ÒQQÜQ[[Y[Ù][YI][ÝË   ][ÝÉÌÍ×ÒQTÝ]×Ò[[YØXÝI][ÝË  ][ÝÐÝÜÙÙXÝ]H][ÈÙ][YHÙTOQSI][ÝÊBBTÙ]Ü  ÌÍ×ÒQTÝ]×Ò[[YØXÝKJBBT]Q[YNÂIÌÍÛ×ÛØXÝÙ[XÝÙ[Ù^TÝÚÙÊ  ÌÍÜ×Û]Ý[YJBRY ÌÍÙÙQ][[BIÌÍÛ×ÛØXÝQ][
    ][ÝÓÛÚ[ÙI][ÝÊBBIÌÍÛ×ÛØXÝQ][
    ][ÝÓÛÛXÚÉ][ÝÊBQ[YTÙ]Ü ÌÍ×ÒQTÝ]×ÔÝXØÙÜÊBT]B[[ÈÏOIÝ×ÒQQÜQ[[Y[Ù][Y

Sends Keystrokes now, which is what I needed.

Posted

Did you try _IEAction($oDiv, "focus")

???

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Posted (edited)

Did you try _IEAction($oDiv, "focus")

???

Dale

I figured that out late last night, and it is so much cleaner and easier. (I was kicking myself when I realized how simple it could be.) Thanks for taking the time to reply.

ss3

edit:

Or even simpler.

$oDiv.focus

Edited by ss3vegeta
Posted

edit:

Or even simpler.

$oDiv.focus

No argument on it being less code. Advantage to _IE functions is consistent error handling.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...