google-chromeautomationsilktest

Silk Test - Record open dialog in Chrome


I'm using silk test 17.5 in order to record a .net script on a web application, in Chrome 51. I have to upload a file by a open dialog box. What is the bets way to achieve it?

Thank you.


Solution

  • Unfortunately it’s not possible to use action recording for uploading the file, but there are ways to achieve this via scripting.

    If your file upload looks like the one on this sample page: http://the-internet.herokuapp.com/upload you can either type the name of the file to be uploaded directly into the upload control:

    With _desktop.BrowserApplication()
      With .BrowserWindow()
        .DomTextField("//INPUT[@id='file-upload']").TypeKeys("c:\temp\test.txt")
        .DomButton("//INPUT[@id='file-submit']").Click()
        Workbench.Verify("test.txt", .DomElement("//DIV[@id='uploaded-files']").Text)
      End With
    End With
    

    Or you can click on the upload control to bring up the "File Open" dialog and then automate that via the Win32 API:

    With _desktop.BrowserApplication()
      With .BrowserWindow()
        .DomTextField("//INPUT[@id='file-upload']").Click()
      End With
    End With
    
    With _desktop.Dialog("@caption='Open'")
      .TextField("@caption='File name:'").SetText("c:\temp\test.txt")
      .PushButton("@caption='Open'").Select()
    End With
    
    With _desktop.BrowserApplication()
      With .BrowserWindow()
        .DomButton("//INPUT[@id='file-submit']").Click()
        Workbench.Verify("test.txt", .DomElement("//DIV[@id='uploaded-files']").Text)               
      End With
    End With