Jump to content
Sign in to follow this  
mpower

Winhttp filling out multi-page form

Recommended Posts

Hi all, question to those who are familiar with Winhttp, in particular _WinHttpSimpleFormFill()

I have a form that I fill out and submit using _WinHttpSimpleFormFill() which then returns a subsequent form based on the first form.

How do I then fill out the subsequent form?

#include "WinHTTP.au3"

$sFile = @ScriptDir & "\test.csv"

$sFileHTM = @ScriptDir & "\Form.htm"

$hSession = _WinHttpOpen('Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0'); create new session
$hConnect = _WinHttpConnect($hSession, "www.server.com") ; connect to server
$sHTM = _WinHttpSimpleFormFill($hConnect, "form.cfm", "name:CFForm_2", "name:FileContents", $sFile, "name:import_vendor", "Generic")

;HERE I NEED TO FILL OUT THE SECOND FORM THAT IS RETURNED IN $sHTM

If $sHTM Then
    MsgBox(64 + 262144, "Done!", "Will open returned page in your default browser now." & @CRLF & _
            "It should show array of uploaded files below the form.")
    $hFileHTM = FileOpen($sFileHTM, 2)
    FileWrite($hFileHTM, $sHTM)
    FileClose($hFileHTM)
    ShellExecuteWait($sFileHTM)
EndIf

Cheers!

Share this post


Link to post
Share on other sites

That's easy. Form-fill function accepts strings of forms (sources) also. You would do this:

include "WinHTTP.au3"

$sFile = @ScriptDir & "\test.csv"

$sFileHTM = @ScriptDir & "\Form.htm"

$hSession = _WinHttpOpen('Mozilla/5.0 (Windows NT 5.1; rv:2.0) Gecko/20100101 Firefox/4.0'); create new session
$hConnect = _WinHttpConnect($hSession, "www.server.com") ; connect to server
$sHTM = _WinHttpSimpleFormFill($hConnect, "form.cfm", "name:CFForm_2", "name:FileContents", $sFile, "name:import_vendor", "Generic")

;HERE I NEED TO FILL OUT THE SECOND FORM THAT IS RETURNED IN $sHTM

; You just have to check that form's action be full URL. If it's not then use StringReplace() or something similar on $sHTM to set it.
$hConnNew = $sHTM
$sHTM = _WinHttpSimpleFormFill($hConnNew, $hSession, ...) ; tada!


If $sHTM Then
    MsgBox(64 + 262144, "Done!", "Will open returned page in your default browser now." & @CRLF & _
            "It should show array of uploaded files below the form.")
    $hFileHTM = FileOpen($sFileHTM, 2)
    FileWrite($hFileHTM, $sHTM)
    FileClose($hFileHTM)
    ShellExecuteWait($sFileHTM)
EndIf

Just make sure "action" of the form that you fill is full address and not in form of "/whatever.asp". If it's relative address then you have to e.g. StringReplace() it before filling the form. Check for errors after calling form filling function.

Edited by trancexx

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  

  • Similar Content

    • By v0id
      I am starting out using AutoIt. Here is a simple form with username and password. I want to check if information entered is valid once user clicks a button.
      My problem now is that it only validates once. E.g.: if I type 5 character username, it will complain it is not 7 character (good). But once I correct that mistake and press the button again it will still say the same thing.
      Do I need to have a loop?
       
      #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) $main = GUICreate("Test Tool", 600, 600) $hyourlabel = GUICtrlCreateLabel("YOUR CREDENTIALS", 30, 10, 256) GUICtrlSetFont($hyourlabel, Default, 600) Local $adminfrejalabel = GUICtrlCreateLabel("Username:", 8, 38, 64, 17) Global $adminfrejaid = GUICtrlCreateInput("", 80, 38, 110, 17) Local $adminpasswordlabel = GUICtrlCreateLabel("Password:", 8, 62, 64, 17) Global $adminpassword = GUICtrlCreateInput("", 80, 62, 110, 17, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) $userButton_Check = GUICtrlCreateButton("VALIDATE", 32, 480, 85, 25) GUICtrlSetOnEvent($userButton_Check, "startvalidation") GUISetOnEvent($GUI_EVENT_CLOSE, "ExitGUI") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func startvalidation() ;CHECK VALIDATIONS $adminfrejaid = GUICtrlRead($adminfrejaid) $adminpassword = GUICtrlRead($adminpassword) If StringLen($adminfrejaid) <> '7' Then MsgBox($MB_SYSTEMMODAL, "User ID", "Please enter exactly 7 characters.") ;Exit EndIf If StringLen($adminpassword) < '5' Then MsgBox($MB_SYSTEMMODAL, "Your Password", "Please enter a valid password.") ;Exit EndIf EndFunc Func ExitGui () Exit ; Exit the program EndFunc  
    • By fastman
      I am struggling with activating the 2nd GUI.  References of https://www.autoitscript.com/wiki/Managing_Multiple_GUIs did not help.
      Gui2 and controls are created, but the buttons are not active.  I have tried to remove extra code.
      Thanks for any help.
      ; ; cabinet maker process to automate MasterCam ; ATP nesting process ; #include <AutoItConstants.au3> #include <Array.au3> ;#include <file.au3> ;#include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> #include <WinAPIFiles.au3> #include <WindowsConstants.au3> ;#include <XML.au3>; If XML library is updated, note that this script requires that save file will overwrite an existing file Opt("GUIOnEventMode", 1) ; 1 = OnEvent mode Opt("WinWaitDelay", 500) ; milliseconds Opt("TrayIconDebug", 1) Opt("WinSearchChildren", 1) Global $hMainGUI Global $hMainGUI2 Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default) If Not IsHWnd($hCallersWindow) Then ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF) Return False EndIf ; Get all list of controls If $bOnlyVisible = Default Then $bOnlyVisible = True If $sStringIncludes = Default Then $sStringIncludes = "" If $sClass = Default Then $sClass = "" $sClassList = WinGetClassList($hCallersWindow) ; Create array $aClassList = StringSplit($sClassList, @CRLF, 2) ; Sort array _ArraySort($aClassList) _ArrayDelete($aClassList, 0) ; Loop $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 If StringLen($sClass) > 0 Then For $i = UBound($aClassList) - 1 To 0 Step -1 If $aClassList[$i] <> $sClass Then _ArrayDelete($aClassList, $i) EndIf Next EndIf For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]") $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}") $aPos = ControlGetPos($hCallersWindow, "", $hControl) $sControlID = _WinAPI_GetDlgCtrlID($hControl) $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible") If $bOnlyVisible And Not $bIsVisible Then $iTotalCounter += 1 ContinueLoop EndIf If StringLen($sStringIncludes) > 0 Then If Not StringInStr($text, $sStringIncludes) Then $iTotalCounter += 1 ContinueLoop EndIf EndIf If IsArray($aPos) Then ;ConsoleWrite("ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF) ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF) Else ;ConsoleWrite("ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) EndIf If Not WinExists($hCallersWindow) Then ExitLoop $iTotalCounter += 1 Next ;MsgBox($MB_SYSTEMMODAL, "title", "check console for control list") EndFunc ;==>GetAllWindowsControls ; ======= Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible = Default, $sStringIncludes = Default, $sClass = Default) ========= Func setNestingOverlay() $ovrWidth = 400 $ovrHeight = 60 $ovrLeft = -1 ;$mcamWindow[0] + $nestControlRelative[0] $ovrTop = -1;$mcamWindow[1] + $nestControlRelative[1]+ 10 $hMainGUI = GUICreate("covering mastercam buttons", $ovrWidth, $ovrHeight, $ovrLeft, $ovrTop, -1, $WS_EX_TOPMOST) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseButton2") Local $iOKButton1 = GUICtrlCreateButton("Continue to gui2", 20, 20, 80) GUICtrlSetOnEvent($iOKButton1, "NestResultButtonOverlay") GUISetState(@SW_SHOW, $hMainGUI) GetAllWindowsControls(WinGetHandle("[ACTIVE]")) ;loop to monitor button click While 1 Sleep(50) ; Sleep to reduce CPU usage WEnd ConsoleWrite(" exit loop setNestingOverlay") EndFunc ;==>setNestingOverlay ;=== 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ======= 2nd gui ==== func NestResultButtonOverlay() $ovrWidth = -1;$mcamWindow[2] - 10 $ovrHeight = 70 ;40 $ovrLeft = -1 ;$mcamWindow[0] + 5 ;+ $nestControlRelative[0] $ovrTop = -1 ;$mcamWindow[1] + $nestControlRelative[1]+ 10 $hMainGUI2 = GUICreate("gui2-- covering nest result buttons", $ovrWidth, $ovrHeight, $ovrLeft, $ovrTop, -1, $WS_EX_TOPMOST) ;width, height, left, top ;GUISetState(@SW_DISABLE + @SW_MINIMIZE, $hMainGUI) ;GUISwitch($hMainGUI2) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseButton2") local $iBackNestingButton = GUICtrlCreateButton("Back to Nesting", 20, 10, 120) GUICtrlSetOnEvent($iBackNestingButton, "backtoNesting") Local $iOKButton2 = GUICtrlCreateButton("Continue for g-Code", 160, 10, 120) GUICtrlSetOnEvent(-1, "generateGCode") ;GUICtrlSetOnEvent($iOKButton2, "generateGCode") Local $iDoneButton2 = GUICtrlCreateButton("Oops go back to vortex", 300, 10, 120) GUICtrlSetOnEvent($iDoneButton2, "CloseButton2") GUISetState(@SW_SHOW, $hMainGUI2) GUISetState(@SW_DISABLE + @SW_MINIMIZE, $hMainGUI) GUISwitch($hMainGUI2) GetAllWindowsControls(WinGetHandle("[ACTIVE]")) While 1 Sleep(50) ; Sleep to reduce CPU usage WEnd ConsoleWrite(" exit loop NestResultButtonOverlay") EndFunc ;==>setNestingOverlay func backtoNesting() msgbox($MB_SYSTEMMODAL, "gui2","backtoNesting") EndFunc Func CloseButton2() msgbox($MB_SYSTEMMODAL, "gui2","CloseButton2") Exit EndFunc func generateGCode() msgbox($MB_SYSTEMMODAL, "gui2","generateGCode") EndFunc ; =========== main =========== main =========== main =========== main =========== main =========== main setNestingOverlay()  
    • By Surya
      Hi everyone its been loooong since I posted here 
      I have been trying to convert this curl executable parameters into autoit using the winhttp com object;
      curl -F data_file=@my_audio_file.mp3 -F model=en-US "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4jdsgjhgghstOGU5YS00OWFhLWghdgjshgdhbshj017###" any ideas guys
       
      PS: I am excited to post here after a looong time
    • By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • By jasontj
      Hello.  I'm working on converting another script from IE to Firefox.  I can't seem to get a handle on the field "Defendant" to fill in a last, first name on this page:
      http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal
      I also can't seem to submit the form.   I've tried the code below... stuff may be commented out that I have tested.
       
          _FFOpenUrl("http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal")    
          _FFLoadWait()
          $oTextFN = _FSObjGet("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_ContentPlaceHolder2_tabSearch_tabCriminal_txtCrimDefendant", "ID")
          
          _FFObj($oTextFN, "value", "Smith, John")    
          $subButton = _FFObjGet("ctl00$ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder2$ContentPlaceHolder2$btnSearch", "name")
          _FFClick($subButton)
          _FFLoadWait()
          
      ;    _FFFormSubmit()
      ;    _FFLoadWait()
       
      Any help from the experts on here would be greatly appreciated.  
       
      Jason
       
       
       
       
×
×
  • Create New...