Jump to content

Send Hotkey to IEAction saveas dialog


Recommended Posts

I am having an issue with using a Send command to send a hotkey. It seems to work if I manually hit the hotkey, but not if I include in the script, like so:

While 1
Local $msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $GUI_Button_Home
_IENavigate($oIE, "http://www.doitbest.com/StoreLocator.dib")
Case $msg = $GUI_Button_Back
_IEAction($oIE, "back")
Case $msg = $GUI_Button_Forward
_IEAction($oIE, "forward")
Case $msg = $GUI_Button_Stop
_IEAction($oIE, "stop")
Case $msg= $Gui_Button_Go
While 1
_IEAction($oIE,"saveas")
sleep(2000)
Send("^s",0)
Send("[ENTER]")

If _IELinkClickByText($oIE,"[Next Stores]") Then
Sleep(20)
Else
_IENavigate($oIE, "http://www.doitbest.com/StoreLocator.dib")
ExitLoop
EndIf
WEnd



EndSelect
WEnd

I have the hotkey.exe that I wrote running while I run this...Basically is sends an abbreviation of a state, the count, and ".html"(for example, KY3.html).

Any suggestions?

Edit...script edit formatted the code weird.

Edited by zsutton92
Link to comment
Share on other sites

I have modified the code to include the hotkey functionality...still not getting the results I want...please help.

; *******************************************************
; Example 1 - Trap COM errors so that 'Back' and 'Forward'
;               outside of history bounds does not abort script
;               (expect COM errors to be sent to the console)
; *******************************************************

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

;setHotKey()
doItData()

Func setHotKey()
HotKeySet("^s","save")
Global $state=InputBox(@ScriptName,"Please enter State Abbreviation")
global $count=0
EndFunc


Func doItData()
setHotKey()
_IEErrorHandlerRegister()
Local $oIE = _IECreateEmbedded()
GUICreate("Embedded Web control Test", 1920, 1080, _
        (@DesktopWidth - 1920) / 2, (@DesktopHeight - 1080) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUICtrlCreateObj($oIE, 10, 40, 900, 750)
Local $GUI_Button_Back = GUICtrlCreateButton("Back", 999, 100, 100, 30)
Local $GUI_Button_Forward = GUICtrlCreateButton("Forward", 1000, 200, 100, 30)
Local $GUI_Button_Home = GUICtrlCreateButton("Home", 1000, 300, 100, 30)
Local $GUI_Button_Stop = GUICtrlCreateButton("Stop", 1000, 400, 100, 30)
Local $Gui_Button_Go= GuiCtrlCreateButton("Go",1000,500,100,30)

GUISetState() ;Show GUI

_IENavigate($oIE, "http://www.doitbest.com/StoreLocator.dib")

; Waiting for user to close the window
While 1
    Local $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            _IENavigate($oIE, "http://www.doitbest.com/StoreLocator.dib")
        Case $msg = $GUI_Button_Back
            _IEAction($oIE, "back")
        Case $msg = $GUI_Button_Forward
            _IEAction($oIE, "forward")
        Case $msg = $GUI_Button_Stop
            _IEAction($oIE, "stop")

Case $msg= $Gui_Button_Go
While 1
_IEAction($oIE,"saveas")
sleep(2000)
Send("^s")
Send("{ENTER}")
If _IELinkClickByText($oIE,"[Next Stores]") Then
Sleep(20)
Else
_IENavigate($oIE, "http://www.doitbest.com/StoreLocator.dib")
ExitLoop
EndIf
WEnd



    EndSelect
WEnd







GUIDelete()

Exit
EndFunc

Func Save()
$count= $count + 1
Send($State&$count&".html")
EndFunc
Link to comment
Share on other sites

Thanks for the response, Larry,

I tried your suggestion...it still does not work. I was using the hotkey as a separate exe and it was not working, so I thought maybe adding it to the script would help...I mean, the hotkey does function inside the script, but when the saveas box is up, it won't accept input from the keyboard. I want it do be automated tho...so thats not that big of a deal I suppose except that it doesnt work.

Edit...

I've noticed that execution of the script stops when the savas dialog appears, then continues once save or cancel is selected. Any way around this?

Edited by zsutton92
Link to comment
Share on other sites

I'm guessing there is no solution to this?

you must use Ctrl+alt+s because only ctrl+s is also using by windows programs.

HotKeySet("^!s","save")
Edited by adnanbaloch

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

Thanks for your input.

I tried the new combination...still no luck. I think the problem is that the script stops and waits for input when the saveas dialog is opened. I guess I could run a second script that looks for that window to be active and then sends the hotkey? I have to compile a list of a bunch of stores and was hoping I would not have to do it manually >_<

Link to comment
Share on other sites

Command Line Parameters in the helpfile...Form 4: execute one line of code...whatever action opens the window must be sent from the new script.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

The dialog is deadlocking your script (it loses control until the dialog is processed). See the second example for _IEAction and my sig for Input type=file suggestions.

Dale

Edited by DaleHohm

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

I could not ever work the code out...just have been running a separate hotkey script and entering it in manually...would be nice to be able to automate this completely though.

Like DaleHohm said, it is possible to do it by using the second example in the help file for _IeAction(). You set focus to the control using _IeAction and then use the ControlSend() and ControlClick() functions to accomplish the rest. Make sure to use WinWait() to wait for the save dialogue box to pop up. This may take you some playing around with to get right but it is definitely more ideal than using a seperate hotkey script.

; *******************************************************
; Example 2 - Same as Example 1, except instead of using click, give the element focus
; and then use ControlSend to send Enter. Use this technique when the
; browser-side scripting associated with a click action prevents control
; from being automatically returned to your code.
; *******************************************************

#include <IE.au3>

$oIE = _IE_Example("form")
$oSubmit = _IEGetObjByName($oIE, "submitExample")
Local $hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($oSubmit, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

; Wait for Alert window, then click on OK
WinWait("Windows Internet Explorer", "ExampleFormSubmitted")
ControlClick("Windows Internet Explorer", "ExampleFormSubmitted", "[CLASS:Button; TEXT:OK; Instance:1;]")
_IELoadWait($oIE)
Link to comment
Share on other sites

To avoid this problem, DO NOT USE _IEAction($oIE,"saveas")

Use the method in the second example for _IEAction instead.

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

My bad, sorry. I didn't read carefully and was giving you instructions for FILE SAVE AS instead of saving the web page.

What are you really trying to accomplish with this script?

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

Well, basically I was being lazy. My boss wants me to gather up these .html files so that he can run it through a program he created that will mine out the data and compile a report for him. I was hoping I could get this automated to the point where all I had to do was set the city, state, and search radius, then let autoit do the rest.

Link to comment
Share on other sites

Instead of doing the Save As, you can do

$sHtml = _IEDocReadHTML($oIE)
$file = FileOpen("your-filename.html", 2)
FileWrite($file, $sHTML)
FileClose($file)

You can also use _IEBodyReadHTML instead to avoid the header area and scripts, etc in the file.

It is also easy to parse the company name and address info out of the HTML with IE.au3, once you work with it a bit more.

Dale

p.s. Also note the structure of the URL you get when you navigate to one of your target pages. You could also easily construct the URL strings that you need and get the file contents with INetGetSource()

Edited by DaleHohm

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

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...