Forum Discussion

Kate's avatar
Kate
Contributor
8 years ago

Handling browser warning regarding .exe file downloading

I need to download an .exe file from certain url (latest Jenkins build).

How can I handle a browser warning kind of 'This type of file can harm your computer' that appears upon clicking the link to the file?

 

I write scripts in Python.

8 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Kate,

     

    If you just need to download a file programmatically, you can use Python's urllib.request.urlretrieve:

    import urllib.request
    
    urllib.request.urlretrieve("http://example.com/myfile.exe", "C:\\myfile.exe")
    • Kate's avatar
      Kate
      Contributor

      Will it work with partial file name? How can I handle it? 

      There will be different versions in my file name in every run...

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        > Will it work with partial file name?

        Could you please provide more details or some example of what do you mean ?

         

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    The general approach is the same as for any other window:

    -- Examine the warning window in the Object Browser and determine its identification properties;

    -- After the link is clicked, wait in a loop until either download starts or the warning window appears;

    -- If the warning window appears, close it to proceed to file download;

    -- In a loop wait until the file is downloaded (consider timeout in order not to stay in a loop forever if download fails for some reason).

     

    Note: identification of the warning window (and, especially, its internal controls) may require MSAA extension to be enabled in TestComplete.

     

    Note 2: usually, warning windows are different for different browsers.

     

    A sample of the similar function (VBScript) to provide you with an idea:

    '-----------------------------------------------------------------------------
    
    Sub BrowserConfirmationWindowClose
      Const cProcName = "BrowserConfirmationWindowClose"
      Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
    
      Dim browser
      Dim oWin
    
      Set browser = Aliases.browser
      Select Case browser.ObjectIdentifier
        Case "iexplore"
          Select Case browser.FileVersionInfo.MajorPart
            Case 7
            Case 8
            Case Else
    'Aliases.browser.BrowserWindow(0).Window("Frame Notification Bar", "", 1).ToolBar("Notification").Button("Close")
              Set oWin = browser.BrowserWindow(0).WaitWindow("Frame Notification Bar", "", -1, 500)
              If (oWin.Exists) Then
                If (oWin.Visible) Then _
                  Call oWin.ToolBar("Notification*").Button("Close").Click
              End If
          End Select
        Case "firefox"
        Case "chrome"
        Case "safari"
      End Select
    End Sub
    '-----------------------------------------------------------------------------
    
    Sub CheckForBrowserConfirmation
      Const cProcName = "CheckForBrowserConfirmation"
      Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "
    
      Dim browser
      Dim oWin, oWin2
    
      Set browser = Aliases.browser
      Select Case browser.ObjectIdentifier
        Case "iexplore"
          Select Case browser.FileVersionInfo.MajorPart
            Case 7
            Case 8
            Case Else
    'Aliases.browser.BrowserWindow(0).Window("Frame Notification Bar", "", 1).ToolBar("Notification").Button("Open")
              Set oWin = browser.BrowserWindow(0).WaitWindow("Frame Notification Bar", "", -1, 500)
              If (oWin.Exists) Then
                If (oWin.Visible) Then _
                  Call oWin.ToolBar("Notification*").WaitButton("Open", 30000).Click
              End If
          End Select
        Case "firefox"
          Set oWin = browser.WaitWindow("MozillaDialogClass", "Opening *", -1, 500)
          If (oWin.Exists) Then
            Call oWin.FindChild("ObjectIdentifier", "Open", 30).Click
          End If
        Case "chrome"
        Case "safari"
      End Select
    End Sub
    '-----------------------------------------------------------------------------