padinski

form submit not working

6 posts in this topic

#1 ·  Posted (edited)

HI all,

I'm updating our addressing database at work, I will receive an excel file with 4 fields; Address id, Field B, Field C & Field D.

There are 2 forms that need to be submitted in IE, the first is to grab the address details using the Address id, once that's submitted fields B,C & D will be updated & the 2nd form submitted.

Occasionally the Address id someone has provided me, may not exist in our database & when I submit the first form, a message box will popup with the following:

"Message from Webpage" "Address id not found" "OK". 

Now my script works fine if all id's exist & require no manual input. It also works if it finds an address that does not exist, in that it will go the next line in the array, however when it goes to an address id that can be found after an address that can't be found it won't submit the 2nd form, I have to manually click submit for the script to continue. Can anyone look at the following to see why it's doing this & see what I need to add?

 

;-----------------------------------------------------------------------------
; Select filepath with message to display in FileOpenDialog.
;-----------------------------------------------------------------------------
Local Const $sMessage = "Select your excel file."
Local $sFilePath = FileOpenDialog($sMessage, "D:\Users\xxxx\Documents\", "Excel (*.xls;*.xlsx;*.csv)|", $FD_FILEMUSTEXIST)
;-----------------------------------------------------------------------------
; Create application object or connect to an already running Excel instance
;-----------------------------------------------------------------------------
Local $oAppl = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF:", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;-----------------------------------------------------------------------------
;open workbook from excel
;-----------------------------------------------------------------------------
$oWorkbook = _Excel_BookOpen($oAppl, $sFilepath, Default, Default, True)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF:", "Error opening '" & $oWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
;-----------------------------------------------------------------------------
;Read array from excel
;-----------------------------------------------------------------------------
Local $aArray1 = _Excel_RangeRead($oWorkbook, Default)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF:", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_ArrayDisplay($aArray1)
;-----------------------------------------------------------------------------
; Turn on progress GUI
;-----------------------------------------------------------------------------
ProgressOn("Progress", "address updates", "0%")
;-----------------------------------------------------------------------------
; counts the number of rows in the array
;-----------------------------------------------------------------------------
$rows = UBound($aArray1) -1
;-----------------------------------------------------------------------------
; script start
;-----------------------------------------------------------------------------
for $c = 1 to $rows
;-----------------------------------------------------------------------------
; Progress calcualtions
;-----------------------------------------------------------------------------
$p=$c/$rows*100
ProgressSet($p,$c&" of "&$rows&" addresses processed")
;-----------------------------------------------------------------------------
;Address id search in IE
;-----------------------------------------------------------------------------
$oIE = _IEAttach("Address")
$oForm1 = _IEFormGetCollection($oIE, 0)
Local $oQuery = _IEFormElementGetObjByName($oForm1, "AddressID")
_IEFormElementSetValue($oQuery, $aArray1[$c][0])
_IEFormSubmit($oForm1)
_IELoadWait($oIE)
WinWaitActive ("Message from Webpage", "", 1)
ControlClick("Message", "OK", "[CLASS:Button;INSTANCE:1]");Confirmation message box, click "ok"
;-----------------------------------------------------------------------------
;Update fieldB in IE
;-----------------------------------------------------------------------------
$oForm2 = _IEFormGetCollection($oIE, 0)
Local $oQuery1 = _IEFormElementGetObjByName($oForm2, "fieldB")
_IEFormElementSetValue($oQuery1, $aArray1[$c][1])
;-----------------------------------------------------------------------------
;Update fieldC in IE
;-----------------------------------------------------------------------------
Local $oQuery2 = _IEFormElementGetObjByName($oForm2, "fieldC")
_IEFormElementSetValue($oQuery2, $aArray1[$c][2])
;-----------------------------------------------------------------------------
;Update fieldD in IE
;-----------------------------------------------------------------------------
Local $oQuery3 = _IEFormElementGetObjByName($oForm2, "fieldD")
_IEFormElementSetValue($oQuery3, $aArray1[$c][3])
;-----------------------------------------------------------------------------
;Update date in IE
;-----------------------------------------------------------------------------
Local $oQuery4 = _IEFormElementGetObjByName($oForm2, "Date")
_IEFormElementSetValue($oQuery4, "01-06-2015");Set to the first of the month
;-----------------------------------------------------------------------------
;Submit form & prepare for next address
;-----------------------------------------------------------------------------
_IEFormSubmit($oForm2)
_IELoadWait($oIE)
WinWaitActive("Message")
ControlClick("Message", "OK", "[CLASS:Button;INSTANCE:1]");Confirmation message box, click "ok"
Sleep(500)
_IENavigate($oIE, "http://intranet/addaddresssearch")
next

 

Edited by padinski

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

anyone with any ideas, i'm wondering if it's this section here causing problems:

_IEFormSubmit($oForm1)
_IELoadWait($oIE)
WinWaitActive ("Message from Webpage", "", 1)
ControlClick("Message", "OK", "[CLASS:Button;INSTANCE:1]");Confirmation message box, click "ok"
;-----------------------------------------------------------------------------

Basically if a window activates after the form's submitted saying "address id does not exist", I need it to click "OK" & go the next line in the array. If that message box doesn't appear after submitting the $oForm1 after the page has loaded I need it to continue the script. Have I gone the right way about this?

Also instead of making the script waiting 1 second to see if the window pops up I would rather the script would go to the next line in the array only if that message box pops up after the first _IELoadWait. I hope that's clear :/

Edited by padinski

Share this post


Link to post
Share on other sites

Another idea:
The return value of WinWaitActive is 0 when the windows was not found and the timeout has expired. Else the window handle is being returned.
So you could check for the return value being <> 0 and then use ControlClick.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks Water I'm pretty new to autoit & slowly getting the hang of things. The script is working for me & you know the old saying "if it aint broke don't fix it". However you're the one with the knowledge & I have used a lot of your advice from looking at other people topics you have posted on (much appreciated by the way). Do you see any issues with my 'fix' & is there more of a benefit doing it your way, or is it simply just an alternate method getting the same result?

Share this post


Link to post
Share on other sites

No issues with your "fix". My code is just another notation of what you have coded.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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