Jump to content

[SOLVED] Handling the IE download file dialog


Recommended Posts

Hi,

I got a solution to deal with the IE download dialog box. But it makes me not really happy and I didn't find any other way. I have one big import target and that is:

- this should work with German and English language of IE or OS (so I use the word "ownload" instead of "download" could be a problem with capital letters)

- and I want to be shure that the correct dialog box is handled

How is it possible to optimize (at about the last 10 lines), regarding the mentioned stuff above ? I don't want to keep any sleep commands there. I would prefere to youse IDs or handles but I didn't got it working.

#include <IE.au3>

ShellExecute ("iexplore.exe", "about:blank")
sleep(5000); usually I use here WinWait ("Leere Seite")
$oIE = _IEAttach ("about:blank", "url")
_IELoadWait ($oIE)
_IENavigate ($oIE, "www.wolfgang-schaedle.de/download/test.php")
_IELoadWait ($oIE)

$o_form = _IEFormGetObjByName ($oIE, "formt")
$download = _IEFormElementGetObjByName ($o_form, "submit")
_IEAction ($download, "click")
$hwnd = _IEPropertyGet ($oIE, "hwnd")
_IEAction ($download, "focus")
Opt("WinTitleMatchMode", 2)
Opt("SendKeyDelay", 30)
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
Sleep (2000)
ControlSend ("Download", "" , "[CLASS:Button; INSTANCE:2]", "!s")
Sleep(2000)
ControlSend ("", "", "[CLASS:Edit; INSTANCE:1]", "C:\Temp\test.gpx" & "{Enter}")
Sleep(3000);this one here is only for testing
_IEQuit($oIE)

Thanks, Wolle

Edited by wolle7

Cheers Wolle

Link to comment
Share on other sites

Is that your website? And if so, do you know what the actual file location is of the file you want to download?

If so, try getting it with INetGet.

It's only a test page for you. I need it for on another side on which you have to login first and you don't know the filename or it's location. The download is initiated by a download button. So it's almost the same here.

Cheers Wolle

Link to comment
Share on other sites

I actually had the idea to use a handle with the two ControlSend commands at the bottom of the script. But how am I able to get the handle from the 'save,open, cancel dialog box' and the 'file save dialog box' ?

Cheers Wolle

Link to comment
Share on other sites

Can you restate your question more clearly please? I don't understand it.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Can you restate your question more clearly please? I don't understand it.

Dale

Thanks for having a look at this. I'll try to ask more clearly.

My posted script seems to work. But I don't like the last few lines:

Sleep (2000)
ControlSend ("Download", "" , "[CLASS:Button; INSTANCE:2]", "!s")
Sleep(2000)
ControlSend ("", "", "[CLASS:Edit; INSTANCE:1]", "C:\Temp\test.gpx" & "{Enter}")

I would like to use here something other than a sleep command e.g. a "WinWait" - but I did not get it working.

and

I would like to use the "ControlSend" combined with a handle to be sure it's the right window. But I have not been able to get the handle of these two windows.

Hopefully my question is now better.

Cheers Wolle

Cheers Wolle

Link to comment
Share on other sites

Are you using the AutoIt Window Info tool to get inforamtion about the windows and controls? You also may be abel to use ControlClick in place of the first ControlSend.

It still isn't very clear what problem you are trying to solve.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for my late replay, I've been on holidays.

Okay give me another try to explain my problem. Just have a look at this screenshot:

Posted Image

Here you see the download dialog box and the fitting Controlinfo.

How am I able to wait till this window is shown and then press the "Speichern" button. (This should also work when I use an english version of windows.)

I guess the best would be to use the handle but how do get this from this dialog box ?

Please let me know if it's still not clear what I am looking for.

Cheers Wolle

Cheers Wolle

Link to comment
Share on other sites

Perhaps there is some language-independant text in Hidden Text... other than that, there is little I can think of other than trying to match on all possible languages.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Perhaps there is some language-independant text in Hidden Text... other than that, there is little I can think of other than trying to match on all possible languages.

Dale

Unfortunatley there is no usuable hidden text.

Posted Image

Isn't there any way to get the handle of this download window ?

Wolle

Cheers Wolle

Link to comment
Share on other sites

Can't you use the Class?

Isn't #32770 independant?

The Class is what I actually use (see my script), but I do not know if the window is already shown or not, so I wait for a predefined time and I use ControlSend with the Class.

Not knowing if the window is yet shown or not is the main problem of this thread.

Cheers Wolle

Cheers Wolle

Link to comment
Share on other sites

Have you looked at the "Window Titles and Text (Advanced)" topic in the helpfile? Click on the "Title special definition" in the docs for WinGetHandle.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Have you looked at the "Window Titles and Text (Advanced)" topic in the helpfile? Click on the "Title special definition" in the docs for WinGetHandle.

Dale

Thanks a lot for that. I guess I got it working with your idea. But there is still a "little" problem. Here the working code:

#include <IE.au3>
#include <Date.au3>

$filenametodownload = "test.gpx"
AutoItSetOption("WinTitleMatchMode", 2)

ShellExecute ("iexplore.exe", "about:blank")
sleep(1500); only for testing purposes will be replaced later with something other
$oIE = _IEAttach ("about:blank", "url")
_IELoadWait ($oIE)
_IENavigate ($oIE, "www.wolfgang-schaedle.de/download/test.php")
_IELoadWait ($oIE)

$o_form = _IEFormGetObjByName ($oIE, "formt")
$download = _IEFormElementGetObjByName ($o_form, "submit")
_IEAction ($download, "click")

;File Save Box
WinWait("ownload",$filenametodownload)
$mydownloadhandle1 = WinGetHandle("ownload",$filenametodownload)
Sleep(2000)
ControlSend ($mydownloadhandle1, "", "[ID:4427]", "!S")

;File Save Dialog Box
WinWait("[CLASS:#32770]", $filenametodownload)
$mydownloadhandle2 = WinGetHandle("[CLASS:#32770]",$filenametodownload)
Sleep(2000)
ControlSend ($mydownloadhandle2, "", "[ID:1001]", "C:\Temp\test" & _Date_Time_GetTickCount() & ".gpx" & "{Enter}")

_IEQuit($oIE)

Without the two "Sleep(2000)" commands it is not working correctly, but I do not want to use any sleep command, because if my computer is busy it is not sure that it's working fine. I prefer doing it on another way, but I do not have any idea what I could do. Does some have any idea to replace these sleep commands with something better ?

Cheers Wolle

Cheers Wolle

Link to comment
Share on other sites

Thanks a lot to the person which one helped me a lot via PM to get a great and working solution.

Cheers Wolle

Here it is:

#include <IE.au3>
#include <Date.au3>
#include <Constants.au3>

;warning: the OS stuff only works under vista when the editor is started with admin rights :(

$_IEErrorNotify = False

$filenametodownload = "test.gpx"
AutoItSetOption("WinTitleMatchMode", 2)

ShellExecute ("iexplore.exe", "about:blank")

While 1
    $oIE = _IEAttach ("about:blank", "url")
    If Not @error Then ExitLoop
    Sleep(100)
WEnd

_IENavigate ($oIE, "www.wolfgang-schaedle.de/download/test.php")

$download = _IEGetObjByName($oIE, "submit")
_IEAction ($download, "click")


While 1
    Local $avArray = WinList()
    For $i = 1 To $avArray[0][0]
        If _WinAPI_GetWindowLong($avArray[$i][1], $GWL_STYLE) = "0x94C80AC4" Then
            ExitLoop(2)
        EndIf
    Next
    Sleep(200)
WEnd

While WinExists($avArray[$i][1])
; $avArray[$i][1] is now holding a handle to the save dialog.
    ControlClick($avArray[$i][1], '', '[CLASS:Button; INSTANCE:2]')
    Sleep(200)
WEnd


;File Save As Dialog Box
While 1
    Local $avArray = WinList()
    If @OSVersion = "Win_VISTA" then $MyStyle = "0x96CC02C4"
    If @OSVersion = "Win_XP" then $MyStyle = "0x96CC20C4"
    $MyStyle = "0x96CC02C4"
    For $i = 1 To $avArray[0][0]
        If _WinAPI_GetWindowLong($avArray[$i][1], $GWL_STYLE) = $MyStyle Then
            ExitLoop(2)
        EndIf
    Next
    Sleep(200)
WEnd
; $avArray[$i][1] is now holding a handle to the save as dialog.
ControlSetText($avArray[$i][1], "", '[CLASS:Edit; INSTANCE:1]', 'C:\temp\test_' & _Date_Time_GetTickCount() & '.gpx')
If @OSVersion = "Win_VISTA" then ControlClick($avArray[$i][1], '', '[CLASS:Button; INSTANCE:1]')
If @OSVersion = "Win_XP" then ControlClick($avArray[$i][1], '', '[CLASS:Button; INSTANCE:2]')

_IEQuit($oIE)

Cheers Wolle

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...