IEGET and Dialog box

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Penguin
Posts: 94
Joined: 26 Feb 2016, 16:02

IEGET and Dialog box

27 Dec 2016, 09:59

Hi all,
I think I have an issue with IEGet and IE dialog boxes. I have a script that monitors a folder for csv files. Once it finds one or more files, the script is supposed to login to a web app and then for each file, it has to click the browse button to upload the selected file and wait for it to finish being processed and repeat. My issue is that my code stops as soon as the "choose file to upload" dialog is opened. At this point, I want to sendinput the string that is the path to the selected file and click the "Open" button.

Code below:

Code: Select all

#Persistent
#SingleInstance Force
SetTitleMatchMode 2

wb := IEGet("Supply Chain Online")

SetTimer, MonitorForFiles2, 15000
return

MonitorForFiles2:
fileSource := "B:\xxx\"
fileDestination := "B:\xxx\old\"

fileCount := ComObjCreate("Scripting.FileSystemObject").GetFolder(fileSource).Files.Count
if(fileCount > 0)
{
	SetTimer, MonitorForFiles2, off
	WinActivate, Internet Explorer
	WinMaximize, Internet Explorer
	sleep, 5000
	wb.visible := true


	
	;click checkbox
	Click 790, 215
	sleep 3000
	;click login button
	wb.Document.All.Submit1.Click()	
	sleep 3000
	
	;click tab
	Click 360, 177
	
	;loop through the files found
	Loop, %fileSource%\*.csv, , 0
	{
		csvfile := fileSource A_LoopFileName
		sleep 5000
		
		;click browse button
		upLoadFile:
		wb.Document.All.fupdTech.Click()

		;Click 575, 343
		;WinWaitActive, Choose File to Upload
		;send file path and name to the browse dialog box
		SendInput, %csvfile%
		;click 249, 197
		sleep, 500
		;click the open button
		Click 625, 565
		WinWaitClose, Choose File to Upload

		sleep 2000
		;click upload button
		Click 660, 340

		loop 600
			{
				if((StrLen(wb.document.getElementById("lblerror").innerHTML)>0) or (StrLen(wb.document.getElementById("jGridTable").Rows.length)>0))
				{
					break
				}
				else{
					sleep 1000
				}
			}
		errorString := ""	
		if(StrLen(wb.document.getElementById("lblerror").innerHTML)>0)
		{
			errorString := wb.document.getElementById("lblerror").innerHTML
		}
		
		errorMsg = Error occurred in reading the contents of file
		IfInString errorString, %errorMsg%
		{
			counter := counter + 1
			if(counter < 3)
			{
				sleep 2000
				goto upLoadFile
			}
		}
		;move file to archive folder
		if FileExist(csvfile) 
		{
			FileMove, %csvfile%, %fileDestination%,1
		}
	}
		sleep 3000
		SetTimer, MonitorForFiles2, on
		;click log off button
		Click 952, 84
}
else{
	return
}

;open 
IEGet(Name="")       
{
    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
        Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
        : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
    For wb in ComObjCreate( "Shell.Application" ).Windows
        If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
            Return wb
}
Last edited by just me on 27 Dec 2016, 10:36, edited 1 time in total.
Reason: Added code tags.
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: IEGET and Dialog box

28 Dec 2016, 07:45

Actually Com wait for fileselectfile done its job, while no other com step gonna work until you select uploadfile, in my case com put whole script to wait so I used separate ahk file with.

Code: Select all

loop{
DetectHiddenWindows, on
WinWait, Choose File
WinActivate, Choose File
ControlSetText, Edit1, %upload%, Choose File        ; Chose file /select file / Open File   use spy to confirm title
winwaitclose, Choose File
}
; main script had same line "winwaitclose, Choose File" just after "select file button" then is trigger upload bottom 
I use above code as separate ahk. some rare cases first file failed to get upload but after first issue all other file have no issue get uploading.
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 278 guests