1

I'm using PowerShell for about a week now. I am able to open a specific URL and fill in my username and password automatically. I can also navigate to a certain page where multiple files can be found to download.

I use the following command to select a certain file to download:

$ie.navigate2('http://www.example.com/resource.aspx?ResourceID=GetDocStoreFile&EntryID=1234')

What happens next is that a second window will open, named "file download". There are three buttons: open, save and close.

I don't want to press the "open" button manually, but would like the script to do that for me and then goes back to the original window to select another file. Any suggestions?

tshepang
  • 12,111
  • 21
  • 91
  • 136
AVB
  • 11
  • 1
  • 1
  • 3

1 Answers1

1

If you use a download URL, I don't think you can interact directly with IE using the COM object, because there's no document. Once the dialog box opens, all of the object's properties become null. You can use the method I posted here: How to perform keystroke inside powershell? AppActivate will work to activate a dialog box by title.

The % represents the the ALT key, so if the underlined letter of the button you want to click is O, you'd invoke SendKeys like this:

$wshell.SendKeys('%O')
Community
  • 1
  • 1
Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
  • Thanks for the reply. I understand your thoughts but so far I can't get it working. I assume it has to do with the AppActivate command. Is it that with this command you will active a certain application? In my case the 'File Download' windows is already active because it pops-up. Basically, nothing is happening. I would appreciate if you can give me some more instructions/suggestions. Otherwise, I have to accept it that I have to press the 'Open' button manually. – AVB Jul 31 '13 at 07:26
  • It wouldn't be active unless you set **$ie.Visible** to $true. But I don't think you even *can* do that in this case, because as I said, if you navigate to a download link, all the properties are nulled out. That's why you need **AppActivate**. I can be more specific if you can be more specific. Add a picture of the screen shot to your question. Also, tell me specifically what you tried that didn't work. – Adi Inbar Jul 31 '13 at 14:45
  • @AndreVermeulen This method does work, I tested it. If you can be more specific than "I can't get it working", I can tell you where the misunderstanding lie. For one thing, "active" doesn't just mean it's running, it means that it's the foreground application you're interacting with. So no, the File Download window is not already active. It starts in the background, and you need to make it the active window with **AppActivate** in order to send keystrokes to it. Did you actually try it? – Adi Inbar Sep 15 '13 at 21:56