0

In IE automation, how to handle window that opens when 'upload files' or 'attach' button clicked through vbscript?

To be clear, I've automated until the 'upload' button pressed. After that I need to fill the file path and open button needs to be pressed in the newly opened window, automatically. Is that any way to handle that window using vbscript or by any other means?

Joseph
  • 1
  • 2
  • The most reliable way is to upload file via XHR POST, it requires some skills, but no IE automation needed. Could you share the web site link you are uploading file to? – omegastripes Nov 01 '15 at 20:09
  • @omegastripes The thing is I need to automate this in IE. And I've started (almost completed) in Vbscript. For this part alone I'm using Sendkeys method which is not at all a good practice. However I can share site details but there's no use in it. Becasuse it can't be accessed by public. Hope you understood :) – Joseph Nov 02 '15 at 17:26
  • Automating IE's window buttons pressing is not VBS was designed to, so you've chosen the hardest way 8). You may try 3rd party components, allowing WinAPI calls within VBS, like Dynawrap. Also take a look at AutoIt. – omegastripes Nov 02 '15 at 18:03

1 Answers1

0

You can use the Wscript Shell object to activate the dialog that is opened when a file upload is initiated. The process for bringing a window into focus looks like this. You'll need to adjust it accordingly to fit your code. Primarily, you need to supply the window title. I'm not on Windows right now to test, but it would typically be something like "Choose File to Upload"

Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Visible = True

Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate objExplorer.Name

Set objShell = Nothing
Set objExplorer = Nothing

You might also try using SendKeys without activating the window first. The browse dialog should be application modal. As long as your webpage tab is activated, it should have focus anyway. Don't forget that buttons can be pressed via their keyboard shorcuts as well.

Nilpo
  • 4,675
  • 1
  • 25
  • 39