neilontherock Posted January 31, 2009 Author Posted January 31, 2009 (edited) I have written the script using only Autoit and have successfully navigated to the asp https site, inputting username and password, selected other options and am now ready to press the "Download" button to initiate the download of the zipped file. The question I have is can I somehow download the file without pressing the download button? Can I used the InetGet function. This function needs the URL and the filename. Will the InetGet work in this case? I'm going to give it a try with your above suggestions. Below is the code I wrote to do this. I've remove the actual site information for security reasons. #include <ie.au3> $obj=_IECreate("https://www.thesecuresite",0) _IELoadWait ($obj) $form=_IEFormGetObjByName($obj,"aspnetForm") $usernameinput=_IEFormElementGetObjByName($form,"ctl00$ctl00$BodyContent$BodyContent$ctl01") $passwordinput=_IEFormElementGetObjByName($form,"ctl00$ctl00$BodyContent$BodyContent$ctl04") $SignIn=_IEFormElementGetObjByName($form,"ctl00$ctl00$BodyContent$BodyContent$SignIn") _IEFormElementSetValue($usernameinput,"theusername") _IEFormElementSetValue($passwordinput,"thepassword") _IEAction ( $SignIn, "click" ) _IELoadWait ($obj) $obj2 =_IEAttach("Web Page Title") _IELoadWait ($obj2) _IELinkClickByText($obj2 ,"Text Box contents") _IELinkClickByText($obj2 ,"Text Box contents") $form2=_IEFormGetObjByName($obj2,"aspnetForm") $Format=_IEFormElementGetObjByName($form2,"ctl00_ctl00_ctl00_BodyContent_BodyContent_BodyContent_ctl01") _IEFormElementOptionselect ($Format,"CSV - Comma-Separated Values",1 ,"byText") #comments-start $StartDownload=_IEFormElementGetObjByName($form2,"ctl00$ctl00$BodyContent$BodyContent$Download") _IEAction ( $DownloadButton ,"click" ) #comments-end Edited February 1, 2009 by neilontherock
herewasplato Posted January 31, 2009 Posted January 31, 2009 ... The question I have is can I somehow download the file without pressing the download button? Can I used the InetGet function. ...I'm not sure.Maybe Dale will stop by :-) [size="1"][font="Arial"].[u].[/u][/font][/size]
neilontherock Posted February 1, 2009 Author Posted February 1, 2009 I'm not sure.Maybe Dale will stop by :-)Thanks...Hoping someone knows the answer the this question. :-)
DaleHohm Posted February 2, 2009 Posted February 2, 2009 I have written the script using only Autoit and have successfully navigated to the asp https site, inputting username and password, selected other options and am now ready to press the "Download" button to initiate the download of the zipped file. The question I have is can I somehow download the file without pressing the download button? Can I used the InetGet function. This function needs the URL and the filename. Will the InetGet work in this case? I'm going to give it a try with your above suggestions.The answer is... it depends. If everything you need is in a URL, then you can use INetGet, but if it relies on session state variables and access setup specifically for your request, then you cannot. You'll need to do some more characterization and testing.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
neilontherock Posted February 2, 2009 Author Posted February 2, 2009 (edited) The answer is... it depends. If everything you need is in a URL, then you can use INetGet, but if it relies on session state variables and access setup specifically for your request, then you cannot. You'll need to do some more characterization and testing.DaleThe INetGet is not an option for me because the site relies on session variables. The only way I can get the script to interact correctly with the Download Dialog and download the file is if a user is logged on. Running a scheduled task as admin will not work. It doesn't fiind the Download Dialog. If anyone knows of a way to make this work, please let me know. Greatly appreciated. Edited February 2, 2009 by neilontherock
DaleHohm Posted February 3, 2009 Posted February 3, 2009 So why are you avoiding the download button? If clicking it steals control from your script, please see the examples for _IEAction 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
neilontherock Posted February 3, 2009 Author Posted February 3, 2009 (edited) So why are you avoiding the download button? If clicking it steals control from your script, please see the examples for _IEActionDaleI am clicking the Download Button and the script will download the file. The problem I'm having is I cannot get the script to work unless a user is logged on and executes it. I have deployed the script to our server and set up a scheduled task to run it. It works if I'm logged on the server but fails if I'm not.I try various things like psexec with the switch for interact with desktop. Not sure what the problem is. The script does connect to I.E and according to the log the WinWait("File Download","", 5) returns 1 but the WinWait("Save As", "", 5) returns 0. Any suggestions?Is there anyway to retrieve extending error information that may give me a hint on what the problem is?Really appreciate any help you can provide. Edited February 3, 2009 by neilontherock
neilontherock Posted February 4, 2009 Author Posted February 4, 2009 I am clicking the Download Button and the script will download the file. The problem I'm having is I cannot get the script to work unless a user is logged on and executes it. I have deployed the script to our server and set up a scheduled task to run it. It works if I'm logged on the server but fails if I'm not.I try various things like psexec with the switch for interact with desktop. Not sure what the problem is. The script does connect to I.E and according to the log the WinWait("File Download","", 5) returns 1 but the WinWait("Save As", "", 5) returns 0. Any suggestions?Is there anyway to retrieve extending error information that may give me a hint on what the problem is?Really appreciate any help you can provide.I have some good news and bad. I was able to get the INetGet to work. How I did this was I manually went to the website, pressed the download button and examined the URL path in the Windows Explorer status bar which included the name of the file. I then took this information and added to the INetGet function and was able to automate the download.The next problem I have now is the author of the website post a new file daily using a GUID and the Date stamp. I.e. 1FA80E23802B413FA60F573667D912DD_20090204_csv.zipSo my INetGet will work fine as long as I can somehow retrieve the filename. Can I somehow retrieve the filename from the status bar after I click the download button or from the Dialog Dialog. If I can do this then the INetGet funtion will work.If I can get this to work it would be awesome.
herewasplato Posted February 7, 2009 Posted February 7, 2009 ... So my INetGet will work fine as long as I can somehow retrieve the filename. ...Have you tried _INetGetSource and/or _IEDocReadHTML to discover that path:http://www.autoitscript.com/forum/index.ph...st&p=637158 [size="1"][font="Arial"].[u].[/u][/font][/size]
neilontherock Posted February 8, 2009 Author Posted February 8, 2009 Have you tried _INetGetSource and/or _IEDocReadHTML to discover that path:http://www.autoitscript.com/forum/index.ph...st&p=637158I get the following error back with _INetGetSource.<html><head><title>Error</title></head><body><head><title>Directory Listing Denied</title></head><body><h1>Directory Listing Denied</h1>This Virtual Directory does not allow contents to be listed.</body></body></html>>Exit code: 0 Time: 8.139
herewasplato Posted February 9, 2009 Posted February 9, 2009 ... and _IEDocReadHTML [size="1"][font="Arial"].[u].[/u][/font][/size]
neilontherock Posted February 9, 2009 Author Posted February 9, 2009 ... and _IEDocReadHTMLNo luck with _IEDocReadHTML. The HTML is the same before and after clicking the download button. I did try the _WinAPI_EnumWindows($fVisible = false). This almost works but I cannot seem to get the name of the file. The text is not available. I do see the filename in the Visible Text section when running the Window Info tool but cannot seem to retrieve it via code. GetWindowText returns an empty string for the Window (which is a ComboBoxEx32 control). If I could somehow get the name of the file from the text of that control I may be able to use INetGet.Very fustrated with this and almost ready to give up. Still not sure why the filename has a ... at the beginning of the Name property on the Download Dialog. It's either because of security or it's too long to be displayed. The filename is always 49 characters long. I.e. 50C749CDDE6E40F692CC1C034352FE2B_20090206_csv.zipI'm wondering if there is some network/http API I could use to capture the incoming file name that is being passed from the server to the client. Still searching for answers.
herewasplato Posted February 10, 2009 Posted February 10, 2009 Okay, back to a regular IE UDF solution... I am clicking the Download Button and the script will download the file. The problem I'm having is I cannot get the script to work unless a user is logged on and executes it. I have deployed the script to our server and set up a scheduled task to run it. It works if I'm logged on the server but fails if I'm not. ...Have you tested this code on a locked box that is running XP? It would be interesting to know if the restrictions are the same for interacting with windows while locked.Another option might be to run a VM on the server that can stay "logged on". [size="1"][font="Arial"].[u].[/u][/font][/size]
neilontherock Posted February 11, 2009 Author Posted February 11, 2009 Okay, back to a regular IE UDF solution... Have you tested this code on a locked box that is running XP? It would be interesting to know if the restrictions are the same for interacting with windows while locked.Another option might be to run a VM on the server that can stay "logged on".No I haven't tried it on XP, tried on Window 2000/2003 server. Both have the same problem. I can interact with the Download Dialog but none of the Windows API functions can find the Save As dialog. Again works fine when a user is logged on and executes the script, has no problem finding and processing the Save As dialog but running the script remotely or with no user logged on fails to find the Save As dialog. To do an INetGet, I need is the complete filename, which is in the Combo Box of the Save As dialog. I tried FindWindow for Save As Dialog (used Autoit window info tool to make sure I have correct Class name), get back a null handle, try Enum Windows (including hidden), after pressing the Save button and logging class name, title and text but it does not report finding the Save As dialog. I wondering if anyone has ever been able to interact with the Save As dialog while running script remotely, no user logged on. I do use the Interact with desktop switch on the psexec command and it's executing as Administrator. It's a simple test for someone to try. Be interested to know if anyone esle can do that.VM wouldn't be an option for me to explore at this point and wouldn't be a valid solution for our production environment even if it did work. But would be interesting to try if I get time. Thanks.I am going to try something else tommorrow, when I press the Save button on the Download Dialog, I noticed that a file( or information about it) may be copied to the temporary internet files location, I may be able to recurse that directory and find the filename after pressing the Save button. I know enough about the filename to find it if it's there.Will let you know if this works. Thanks for all you help. Need a nap now...
Bert Posted February 11, 2009 Posted February 11, 2009 May I make a suggestion? Firefox has a Web Developer addon that should give you the info on the file. The Vollatran project  My blog: http://www.vollysinterestingshit.com/
neilontherock Posted February 12, 2009 Author Posted February 12, 2009 May I make a suggestion? Firefox has a Web Developer addon that should give you the info on the file.Thanks. I didn't even know that existed. I took a breif look at it and if the marco will download the file when no user is logged on then this may be an option. Looks like you can run it from the command prompt or in batch. Will give it a try tommorrow and see if it works. Will let you know.Thank-you.
neilontherock Posted February 13, 2009 Author Posted February 13, 2009 I took a look at the Firefox Marcos, neat stuff but I want to try my previous theory first. We'll, I have great news. I got it to work with INetGet. I was able to find the filename. What Windows does when you run a script with no user logged on it writes the name of the file in C:\WINDOWS\TEMP\Temporary Internet Files not C:\Documents and Settings\<user>\Local Settings\Temporary Internet Files (based on Window 2003 Server). So because my script can interact with the Download Dialog, when I click the Download button on the ASP.NET page, I wait for the Download dialog, when it appears I then do a recursive file search through C:\WINDOWS\TEMP\Temporary Internet Files looking for the file. I know enough about the file name to uniquely identify it. Once I find it, I store the file name to a variable and press the Cancel button on the Dialog dialog (as soon as I press Cancel, Windows automatically deletes the file from C:\WINDOWS\TEMP\Temporary Internet Files). Now that I have the filename, I call INetget and my file successfully downloads. Woo Hoo! This has been a great exercise and I am very thankful for everyone who took the time to read this article. Hopefully, it will help someone else. Thanks, Neil
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now