Forum Discussion

Arnelys's avatar
Arnelys
Occasional Contributor
2 years ago

How can I open a notepad downloaded from the browser?

I'm running a test with scripts, using VBScripts. The test consists of downloading a browser notepad, opening it, checking content and closing it. The notepad is downloaded but I can't open it automatically, it shows as a downloaded item at the bottom of the browser, is there any way to open it?

 


I tried using the following


Set p = Sys.Process("notepad")
Set Edit = p.Window("Notepad").Window("Edit")
ReadFileLines = Edit.wText
p.Close

This works perfectly for me if I manually click on the downloaded notepad

  • That makes it slightly tricky. Is there any way of figuring out the format of the filename, to open? Otherwise the other solution is to add your browser WndClass property value to MSAA in Project Settings. Here, I've added Chrome WndClass property value,

    This will expose the browser UI controls in TC.

     

    Ensure you have an application associated with the file type.

  • I found the final solution. It will work for when the file has a dynamic name or not, I leave you step by step

     

    1. Do what is indicated in this link to interact with the download bar of the browser as an object, recognized by Object Spy

    2. Use the Click action on the object, if the file has a dynamic name (which is never the same) follow steps 3 and 4

     

    3. Object spy provides the mapped name of the object, complete up to the filename, you must remove the last child which is the file itself and only handle the browser download bar as the object

    I show you with image and example:

    The full mapped name of the object (downloaded file) is as follows:

    Aliases.browser.Form("Acquisition Shipment Detail - Google Chrome").Pane("Acquisition Shipment Detail - Google Chrome").Pane(0).Pane(0).Pane(1).Grouping("Downloads bar").Grouping("FileName.")

    You must eliminate the part marked in italics, in this way the object that you will handle will be the download bar of the browser

     

    4. When performing the Click action you must include the ClientX, ClientY parameters, these coordinates are of the object itself and not of the screen. More information about Click(ClientX, ClientY) here

    In my case, the code was as I show you below, maybe it is not the most optimal but I am learning:

    (i'm using VBScript)

    dim blnTest
    set blnTest = Aliases.browser.Form("Acquisition Shipment Detail - Google Chrome").Pane("Acquisition Shipment Detail - Google Chrome").Pane(0).Pane(0).Pane(1).Grouping("Downloads bar")
    call blnTest.Click(10,20)

     

    Note: The coordinates 10,20 of the browser bar is the upper left corner of the bar

     

    A pleasure to share my experience on this topic that gave me so many headaches

    🙂

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    That makes it slightly tricky. Is there any way of figuring out the format of the filename, to open? Otherwise the other solution is to add your browser WndClass property value to MSAA in Project Settings. Here, I've added Chrome WndClass property value,

    This will expose the browser UI controls in TC.

     

    Ensure you have an application associated with the file type.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Here's a small example based on the following website https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download, which uses wildcard for the filename.

    function DownloadIT()
    {
        // URL https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download
        var page = Aliases.browser.Page("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download").FindElement("#iframeResult");
        var image = page.FindElement("//img[contains(@src, 'myw3schoolsimage.jpg')]");
        image.Click();
        aqUtils.Delay(1000);
        
        var tabpage = Aliases.browser.BrowserWindow(0).Pane("W3Schools Tryit Editor - Google Chrome");
        // Using wildcard for Grouping and Button
        var downloadBtn = tabpage.Pane(0).Pane(0).Pane(1).Grouping("Downloads bar").Grouping("*").Button("*");
        // Filename
        Log.Message(downloadBtn.Caption);
        // Click button
        downloadBtn.Click();
    }

     

    The above coding is in JavaScript, and will click the button regardless of name.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Just to clarify,

    "downloading a browser notepad" - notepad is a Windows application and not a browser.

    "The notepad is downloaded" - a file is downloaded from the browser and not notepad.

     

    From the browser, when you download a file, it usually stores the file in your Downloads folder. If its a text file, you can use Reading Text Files to read the contents of it. No need to use Notepad to open the file.

    • Arnelys's avatar
      Arnelys
      Occasional Contributor

      I omitted an important detail, the name of the .txt file that is downloaded is never the same because it is made up of a text string plus the date

  • Arnelys's avatar
    Arnelys
    Occasional Contributor

    It's just translator's problem. The thing is that from Chrome the test downloads a .txt then I need to open it to verify something in its content and close it.

    I will try your solution and tell you if it works

    Thanks! 🙂

  • Arnelys's avatar
    Arnelys
    Occasional Contributor

    The format is three letters that are always the same, for example: ABC+today's date+ consecutive (I still don't know where it comes from but I could investigate in the code)


    I was looking yesterday at the way that you tell me about WndClass property but I still had the hope of finding another way.
    I leave here the link of the article that I found, maybe it will be useful for others

    https://community.smartbear.com/t5/TestComplete-Technical-Articles/TestComplete-Interact-with-the-Chrome-download-bar/ta-p/234107

     

    Thank you so much! I appreciate your attention and help

     

  • Arnelys's avatar
    Arnelys
    Occasional Contributor

    I wanted to tell everyone that I was actually a bit afraid that the question of interacting with the Chrome download bar was going to be a bit more complicated, but it was very easy and I managed to get Object Spy to see my downloaded file. Now I don't know what else to do but that's another investigation lol

    Note: I don't think this will be my solution either because with the spy object at the end is the name of the file that is downloaded, which in my case is dynamic as I had commented. I will try to access the object without including the file name and I will tell you how it went

     

     

     

  • Arnelys's avatar
    Arnelys
    Occasional Contributor

    I found the final solution. It will work for when the file has a dynamic name or not, I leave you step by step

     

    1. Do what is indicated in this link to interact with the download bar of the browser as an object, recognized by Object Spy

    2. Use the Click action on the object, if the file has a dynamic name (which is never the same) follow steps 3 and 4

     

    3. Object spy provides the mapped name of the object, complete up to the filename, you must remove the last child which is the file itself and only handle the browser download bar as the object

    I show you with image and example:

    The full mapped name of the object (downloaded file) is as follows:

    Aliases.browser.Form("Acquisition Shipment Detail - Google Chrome").Pane("Acquisition Shipment Detail - Google Chrome").Pane(0).Pane(0).Pane(1).Grouping("Downloads bar").Grouping("FileName.")

    You must eliminate the part marked in italics, in this way the object that you will handle will be the download bar of the browser

     

    4. When performing the Click action you must include the ClientX, ClientY parameters, these coordinates are of the object itself and not of the screen. More information about Click(ClientX, ClientY) here

    In my case, the code was as I show you below, maybe it is not the most optimal but I am learning:

    (i'm using VBScript)

    dim blnTest
    set blnTest = Aliases.browser.Form("Acquisition Shipment Detail - Google Chrome").Pane("Acquisition Shipment Detail - Google Chrome").Pane(0).Pane(0).Pane(1).Grouping("Downloads bar")
    call blnTest.Click(10,20)

     

    Note: The coordinates 10,20 of the browser bar is the upper left corner of the bar

     

    A pleasure to share my experience on this topic that gave me so many headaches

    🙂