Forum Discussion

nb_autoTester's avatar
nb_autoTester
Occasional Contributor
9 years ago

Changing the location in Save As dialogue popup

Hi all,

 

I'm trying to download a file from a webpage using IE as my browser. How it works is, I click a link called Download Selected File and then I'm prompted with the small bar at the bottom of the page that says..

 

    "Do you want to open or save...." 

 

I click the arrow next to Save, and then click Save As. 

 

I'm then prompted with the Save As window, which is where I would like to change the location. What I originally planned on doing is adding the location field and setting it's text to the location that I want, but the object does not have any SetText methods.

 

I've used Record (script) to hit all of these objects, if there's another (better) way please share.

 

Here's what I've got now:

 

Sub Test1
  Dim browser, loc
  Set browser = Aliases.browser
  'Click the arrow next to Save to display the drop down   
  Call browser.BrowserWindow.FrameNotificationBar.Notification.Save.Item.Click(6, 12)
  'Click Save As
  Call browser.wnd32768.Click(69, 33) 
   
  'Get our location field object
  Set loc = Aliases.browser.dlgSaveAs.WorkerW.ReBarWindow32.AddressBandRoot.msctls_progress32.BreadcrumbParent.location_bar
  'No way to set it's text.
   loc.SetText?
End Sub

 

3 Replies

    • nb_autoTester's avatar
      nb_autoTester
      Occasional Contributor

      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

        

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        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.

        '-----------------------------------------------------------------------------

         
        Function SystemDialogFileSaveHandle(ByVal strFileFullName)
          Const cProcName = "SystemDialogFileSaveHandle"
          Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
         
          Dim browser
          Dim UploadFileWindow
          Dim button, button2
          Dim tmpControl
          Dim FileName, FullFileName
         
          SystemDialogFileSaveHandle = Empty
         
          ' handle notification bar window
          ' 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)
         
        ' Aliases.browser.BrowserWindow(0).Window("Frame Notification Bar", "", 1).ToolBar("Notification").Text("Notification bar Text").Value
                  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
         
            Case "firefox"
              Set UploadFileWindow = browser.WaitAliasChild("MozillaDialog", 30000)
              Set button = UploadFileWindow.FindChild( _
                  Array("ObjectType", "ObjectIdentifier"), Array("radio", "save"), 30)
              button.Click
         
              FileName = UploadFileWindow.FindChild( _
                  Array("ObjectType", "ObjectIdentifier"), Array("description", "location"), 30).tooltipText
         
              Set button = UploadFileWindow.FindChild( _
                  Array("ObjectType", "ObjectIdentifier"), Array("button", "OK"), 30)
              Call button.WaitProperty("Enabled", True, Project.Variables.pvtPageTimeout)
              button.Click
         
            Case "chrome"
              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
        '-----------------------------------------------------------------------------