Sign in to follow this  
Followers 0
icarustu

SaveAs dialog won't accept my sendkeys

11 posts in this topic

I hope someone can tell this newbie where he is going wrong. Autoit is awesome but this just isn't working for me.

I am trying to get a succession of charts created via an IE page and save to my local folder. I can do all of this with mouse clicks and it works fine. The below script does the same using _IE calls, avoiding mouse usage. But when I try and send text to the "save as" dialog that pops up when I try to save the chart, sendkeys does not do anything. What am I missing?

#include <Date.au3>

#include <Array.au3>

#include <IE.au3>

Opt("WinWaitDelay", 200)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

Dim $ShareArray

dim $destFolder

Dim $s

Dim $oImg

Dim $oDoc

Dim $oIE

$hares = "UKX;AIEA"

;"UKX;AIEA;ATK;AV.;BA.;BAY;BYR;BGC;EBT;GOC;HCM;IPR;PFD;QQ;RR;SBRY;SPI;SRDR;SGC;TT;ULVR"

; FTSE 100 code is UKX, but needs special treatment because prefix is $GB, not just GB

$ShareArray=StringSplit($hares,";")

$destFolder=FileSelectFolder("Select destination folder:","",1,"C:\TEMP")

for $i=1 to $ShareArray[0]

$ymbol=$ShareArray[$i]

if $ymbol="UKX" then

$s="$GB:" & $ymbol

Else

$s="GB:" & $ymbol

endif

$url="http://data.moneycentral.msn.com/scripts/chrtsrv.dll?symbol=" & $s & "&E1=1&LPR=2&C1=0&C2=1&D5=0&D2=0&D4=1&width=612&height=320&CE=0&CF=" & """0""" & "%20border=" & """0""" & "%20width=" & """612""" & "%20height=" & """258""" & "%20alt=""" & """%20galleryimg=" & """no"""

$oIE = _IECreate ($url)

$oDoc = _IEDocGetObj ($oIE)

$oImg=_IETagNameAllGetCollection($oDoc,0)

$a = $destFolder & "\" & @year & @mon & @mday & "_" & $ymbol & ".gif"

_IEAction ($oImg, "saveas")

send($a)

Sleep(2500)

_IEQuit($oIE)

next

;Finished

Exit

Any suggestions gratefully received!

icarustu

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is very strange. I put a consolewrite of the $a variable in before the _IEAction and the variable $a is correctly displayed with the full file name desired. However, when the same consolewrite line is placed after the _IEAction line it doesn't execute at all and nothing is displayed in the console. Weird. Hopefully there is someone that is better with the IE Management functions than I am. I tried declaring the $a variable but it still didn't work.

If you comment out the "send($a)" line it still shows "chrtsrv.gif" in the "save picture" dialog box. Where is that string coming from? I am running vista so I have IE7 and don't know if that could be the problem.

#include <Date.au3>
#include <Array.au3>
#include <IE.au3>
Opt("WinWaitDelay", 200)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)

Dim $ShareArray
dim $destFolder
Dim $s
Dim $oImg
Dim $oDoc
Dim $oIE
$hares = "UKX;AIEA"
;"UKX;AIEA;ATK;AV.;BA.;BAY;BYR;BGC;EBT;GOC;HCM;IPR;PFD;QQ;RR;SBRY;SPI;SRDR;SGC;TT;ULVR"
; FTSE 100 code is UKX, but needs special treatment because prefix is $GB, not just GB
$ShareArray=StringSplit($hares,";")

$destFolder=FileSelectFolder("Select destination folder:","",1,"C:\TEMP")
for $i=1 to $ShareArray[0]
$ymbol=$ShareArray[$i]
if $ymbol="UKX" then 
$s="$GB:" & $ymbol
Else
$s="GB:" & $ymbol
endif
$url="http://data.moneycentral.msn.com/scripts/chrtsrv.dll?symbol=" & $s & "&E1=1&LPR=2&C1=0&C2=1&D5=0&D2=0&D4=1&width=612&height=320&CE=0&CF=" & """0""" & "%20border=" & """0""" & "%20width=" & """612""" & "%20height=" & """258""" & "%20alt=""" & """%20galleryimg=" & """no"""

$oIE = _IECreate ($url)
$oDoc = _IEDocGetObj ($oIE)
$oImg=_IETagNameAllGetCollection($oDoc,0)
$a = $destFolder & "\" & @year & @mon & @mday & "_" & $ymbol & ".gif"
ConsoleWrite("Before $a= " & $a & @LF)
_IEAction ($oImg, "saveas")
ConsoleWrite("After $a= " & $a & @LF)
send($a)
Sleep(2500) 

_IEQuit($oIE)
next
;Finished
Exit
Edited by simusphere

Share this post


Link to post
Share on other sites

The function _IEAction ($oImg, "saveas") doesn't return until the path has been entered and the dialog closes so your script cannot fill the path in.

To get round this you could have another script compiled say, which fills the details in for you. The second script would need to wait till the "Save Picture" window was active, then wait till is didn't exist for each entry. You could run the second script with a parameter which was the $a string. The second script could terminate once it had done it's job.

Alternatively, you could start the second script, send it a message when you wanted a path entered the next time the "Save Picture" window appeared, and kill it when done with it.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The function _IEAction ($oImg, "saveas") doesn't return until the path has been entered and the dialog closes so your script cannot fill the path in.

To get round this you could have another script compiled say, which fills the details in for you. The second script would need to wait till the "Save Picture" window was active, then wait till is didn't exist for each entry. You could run the second script with a parameter which was the $a string. The second script could terminate once it had done it's job.

Alternatively, you could start the second script, send it a message when you wanted a path entered the next time the "Save Picture" window appeared, and kill it when done with it.

I've never used _IEAction, but is it possible to have an adlib function fill this field in? Or does adlib not run while this function is still out?

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

I've never used _IEAction, but is it possible to have an adlib function fill this field in? Or does adlib not run while this function is still out?

Good idea but unfortunately Adlib is blocked while waiting for the dialogue to close.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

The function _IEAction ($oImg, "saveas") doesn't return until the path has been entered and the dialog closes so your script cannot fill the path in.

To get round this you could have another script compiled say, which fills the details in for you. The second script would need to wait till the "Save Picture" window was active, then wait till is didn't exist for each entry. You could run the second script with a parameter which was the $a string. The second script could terminate once it had done it's job.

Alternatively, you could start the second script, send it a message when you wanted a path entered the next time the "Save Picture" window appeared, and kill it when done with it.

Thanks all you guys who tried to help.

Martin, I am at a bit of a loss as to what form that second script would take. I want to avoid using mouse clicks at all costs. I assume that the name chrtsrv.gif is filled in by the dll that is called in the url. Can you give me any more guidance on this please? I am surprised that none of the AutoIT commands I have tried (and I have tried quite a few!) will interact with the dialog.

Share this post


Link to post
Share on other sites

"saveas" is of questionable value because of this issue with stalling out the script.

It isn't clear to me exactly what you are trying to accomplish... are you trying to save the full document HTML to a file? If so, look at _IEDocReadHTML

Also look atht e second example for _IEAction that provides an approach to avoud the script stalling.

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

Share this post


Link to post
Share on other sites

"saveas" is of questionable value because of this issue with stalling out the script.

It isn't clear to me exactly what you are trying to accomplish... are you trying to save the full document HTML to a file? If so, look at _IEDocReadHTML

Also look atht e second example for _IEAction that provides an approach to avoud the script stalling.

Dale

I am trying to capture a whole raft of charts produced by the site for each of a number of share epic codes. The charts are generated by a serverside dll called within the html source code. I am only interested in the chart, not the underlying web page. I capture these charts monthly for our share club meeting and publish them in a single document that shows progress in our portfolio holdings.

My help file on _IEAction only gives one example. Where can I find this second example?

Share this post


Link to post
Share on other sites

I am trying to capture a whole raft of charts produced by the site for each of a number of share epic codes. The charts are generated by a serverside dll called within the html source code. I am only interested in the chart, not the underlying web page. I capture these charts monthly for our share club meeting and publish them in a single document that shows progress in our portfolio holdings.

My help file on _IEAction only gives one example. Where can I find this second example?

The latest Beta is 3.2.11.1 and that has a second example.

Here is the code with my suggestion which I have tested.

First thing you need to do is compile this first code and save it as spsend.exe in the same folder as your script.

;spsend.au3 to be compiled to spsend.exe
;needs some error checking added 

If $cmdline[0] = '' Then Exit
WinWait("Save Picture")
Sleep(200)
Send($cmdline[1])
Send("{ENTER}")
While WinExists("Save Picture")
sleep(20)
WEnd

Below is the modified version of your code which will call the exe and save the gifs. You will however be prompted if the file name already exists so you will have to add code to avoid that maybe.

#include <Date.au3>
#include <Array.au3>
#include <IE.au3>
Opt("WinWaitDelay", 200)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)

Dim $ShareArray
Dim $destFolder
Dim $s
Dim $oImg
Dim $oDoc
Dim $oIE
$hares = "UKX;AIEA"
;"UKX;AIEA;ATK;AV.;BA.;BAY;BYR;BGC;EBT;GOC;HCM;IPR;PFD;QQ;RR;SBRY;SPI;SRDR;SGC;TT;ULVR"
; FTSE 100 code is UKX, but needs special treatment because prefix is $GB, not just GB
$ShareArray = StringSplit($hares, ";")

$destFolder = FileSelectFolder("Select destination folder:", "", 1, "C:\TEMP")
For $i = 1 To $ShareArray[0]
    $ymbol = $ShareArray[$i]
    If $ymbol = "UKX" Then
        $s = "$GB:" & $ymbol
    Else
        $s = "GB:" & $ymbol
    EndIf
    $url = "http://data.moneycentral.msn.com/scripts/chrtsrv.dll?symbol=" & $s & "&E1=1&LPR=2&C1=0&C2=1&D5=0&D2=0&D4=1&width=612&height=320&CE=0&CF=" & """0""" & "%20border=" & """0""" & "%20width=" & """612""" & "%20height=" & """258""" & "%20alt=""" & """%20galleryimg=" & """no"""

    $oIE = _IECreate($url)
;#cs
    $oDoc = _IEDocGetObj($oIE)
    $oImg = _IETagNameAllGetCollection($oDoc, 0)
    $a = $destFolder & "\" & @YEAR & @MON & @MDAY & "_" & $ymbol & ".gif"
    Run("spsend.exe " & $a,@ScriptDir);this will wait for the "Save Picture window then send $a to it
    _IEAction($oImg, "saveas")

    _IEQuit($oIE)
    
Next
;Finished
Exit

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

That's brilliant Martin, thanks very much. I will try that when I get home.

Bugger that, I couldn't wait. It works perfectly.

I couldn't have asked for a better or more timely response. This forum rocks!

Edited by icarustu

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Does this work with IE6 ?

I'm trying something like Martin's script, but the Save as dialog that pops up is going to save the html page, not the images of the web page that I'm trying...

#include <IE.au3>
$oIE = _IECreate ("http://www.dpchallenge.com")
_IELoadWait ($oIE)

$oDoc = _IEDocGetObj($oIE)
$oImg = _IETagNameAllGetCollection($oDoc, 0)
_IEAction ($oImg, "saveas")
Edited by piratao2

Share this post


Link to post
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
Sign in to follow this  
Followers 0