Jump to content
Sign in to follow this  

Entering data in editbox on website

Recommended Posts


I must be overlooking the obvious, but how do you enter data in an editbox on a webpage? I looked at using _IEFormElementSetValue but the editbox is not contained within a form so it does not work.

Share this post

Link to post
Share on other sites

Never mind, I had my head my my a**. There is a form element on the website. The spy tool I was using did not display some information correctly and that confused me. Once I properly used the _IEFormElementSetValue everything worked just fine.

Its amazing how you can waste an hour researching the simplest thing in the world. Of course, 2 minutes after posting on here you figure it out on your own.

Share this post

Link to post
Share on other sites

The following program helps me locate the forms and elements in a web page

I made it loop so that I can enter manually info in the textboxes and then I see where my text went

#include <IE.au3>
$sUrl = "http://www.autoitscript.com/forum/index.php?app=core&module=global&section=login"

Func _AnalyzeWebPage($sUrl, $visible = 1)
Local $txt, $i, $j, $oIE, $oForms, $iNumForms, $oForm, $oElements, $iNumElements
_IEErrorHandlerRegister ()    ;else calling $oElement.name sends error if element has no name
$oIE = _IECreate($sUrl, 0, $visible)
$oForms = _IEFormGetCollection($oIE)
$iNumForms = @extended
$txt = $txt & "There are " & $iNumForms & " forms on this page" & @CRLF
For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE, $i)
    $txt = $txt & "Form-" & $i & "=" & $oForm.name & @CRLF
    $oElements = _IEFormElementGetCollection($oForm)
    $iNumElements = @extended
    $txt = $txt & "There are " & $iNumElements & " elements on this form" & @CRLF & _
      "  Element-Idx:Name=Value" & @CRLF
    For $j = 0 To $iNumElements - 1
        $oElement = _IEFormElementGetCollection($oForm, $j)
        $txt = $txt & "  Element-" & $j & ":" & $oElement.name & "=" & _IEFormElementGetValue($oElement) & @CRLF
_PutTextInNotepad ($txt, 1)
;ConsoleWrite ($txt)
Until InputBox ("Analyze Page", "Exit (y/n)?") = "y"
EndFunc   ;==>

Func _PutTextInNotepad($txt, $Overwrite = 0)
    Local $Title = "LogFile", $oldtxt = ""
    If Not WinExists($Title) Then
        Local $iPid = Run("notepad.exe")
        Local $hWnd = _ProcessGetHWnd($iPid)
        WinSetTitle($hWnd, "", $Title)
    If $Overwrite = 0 Then $oldtxt = ControlGetText($Title, "", "Edit1")
    ControlSetText($Title, "", "Edit1", $txt & $oldtxt)
EndFunc   ;==>_PutTextInNotepad

Func _ProcessGetHWnd($iPid, $iOption = 1, $STitle = "", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
    While 1
        ; Get list of windows
        $aWin = WinList($STitle)
        ; Searches thru all windows
        For $i = 1 To $aWin[0][0]
            ; Found a window owned by the given PID
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                ; Option 0 or 1 used
                If $iOption = 1 Or ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]
                    ; Option 2 is used
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
        ; If option 2 is used and there was matches then the list is returned
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
        ; If timed out then give up
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop
        ; Waits before new attempt
    ; No matches
    Return 0
EndFunc   ;==>_ProcessGetHWnd

Share this post

Link to post
Share on other sites

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
Sign in to follow this