Forum Discussion
Hi AlexKaras
First off, thanks for the information! A few things with the SaveFile method.
1) Is it possible to just change the location of where we want to save the file, but not the file name? Right now, the file name is being set to the path where we want to save. It does however navigate to the correct path, I would just like to keep the name the default of what it is in the prompt.
2) The cursor ends up ON the Save button, but never clicks it. I have to explicitly click the Save button. All examples of SaveFile that I've seen don't include this. Any ideas?
Here is my code:
Sub Test1 Dim browser, location, ldap 'Get the currently logged in user's ldap. ldap = CreateObject("WScript.Network").UserName 'Get browser object Set browser = Aliases.browser 'Click the small arrow next to the Save Button to display other Save options Call browser.BrowserWindow2.FrameNotificationBar.Notification.Save.Item.Click(10, 12) 'Click Save As Call browser.wnd32768.Click(79, 33) 'The location where we want to save this file location = "J:\SavedFiles\"& ldap 'SaveFile method will change location and prepare to Save Aliases.browser.dlgSaveAs.SaveFile location 'Click Save button Sys.Browser("iexplore").Window("#32770", "Save As", 1).Window("Button", "&Save", 1).Click
Hi,
.SaveFile() method does all required actions internally and there is no need in explicit button click.
I assume that 'location' in your code sample contains only a path and you want to preserve the file name suggested by the system. When I had this case, I got the file name from the notification window displayed by the browser, combined it with the path and then just passed the obtained full file name to the SaveFile method.
This was done in the function (VBScript) that follows below. Hope it will help.
'-----------------------------------------------------------------------------
Const cProcName = "SystemDialogFileSaveHandle"
Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
Dim UploadFileWindow
Dim button, button2
Dim tmpControl
Dim FileName, FullFileName
' For cross-browser specifics:
' http://support.smartbear.com/articles/testcomplete/cross-browser-testing/
' http://smartbear.com/forums/f75/t76579/click-on-short-time-pop-window-(e-g-ie9-noti/
' http://smartbear.com/forums/f75/t60772/ie-8-file-download-box-save-button-not-gettin/
' http://smartbear.com/forums/f75/t60730/ie-8-save-button-is-visible-on-screen-but-vi/
Set browser = Aliases.browser
Select Case browser.ObjectIdentifier
Case "iexplore"
Select Case browser.FileVersionInfo.MajorPart
Case 7
Case 8
Case Else
' Set UploadFileWindow = browser.FindChild("ObjectIdentifier", "Notification*", 30)
Set UploadFileWindow = BrowserWindowByPageGet(GetPage()).FindChild("ObjectIdentifier", "Notification*", 30)
FileName = ""
With Project.Variables.pvtRe
.Expression = "(?g).+ (\w+\.\w+) \(.+"
If (.Exec(UploadFileWindow.Text("Notification bar Text").Value)) Then
FileName = .Match(1)
End If
End With
Set button = UploadFileWindow.FindChild( _
Array("ObjectType", "ObjectIdentifier"), Array("SplitButton", "Save"), 30)
Set button2 = button.FindChild("ObjectType", "DropDownButton", 30)
button2.Click
browser.Popup("Context").MenuItem("Save as").Click
End Select
Set UploadFileWindow = browser.WaitAliasChild("MozillaDialog", 30000)
Set button = UploadFileWindow.FindChild( _
Array("ObjectType", "ObjectIdentifier"), Array("radio", "save"), 30)
button.Click
Array("ObjectType", "ObjectIdentifier"), Array("description", "location"), 30).tooltipText
Array("ObjectType", "ObjectIdentifier"), Array("button", "OK"), 30)
Call button.WaitProperty("Enabled", True, Project.Variables.pvtPageTimeout)
button.Click
Set UploadFileWindow = browser.FindChild("WndClass", "#32770", 30)
FileName = UploadFileWindow.FindChild("WndClass", "Edit", 30).wText
End Select ' browser.ObjectIdentifier
FullFileName = aqFileSystem.IncludeTrailingBackSlash(Sys.OSInfo.TempDirectory) & FileName
Call SystemDialogFileSave(FullFileName)
SystemDialogFileSaveHandle = FullFileName
End Function
'-----------------------------------------------------------------------------