Jump to content

form submit not working


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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