Jump to content

Trying to upload a file to a web page, in the background.


Recommended Posts

I'm trying to upload a file to a web page, in the background (ie: no windows visible to the user).

The problem I have with it, is that even when you steal from the docs, and use '_IEAction($oIE, "invisible")', it's not _truly_ invisible. It pops up for a second, then it vanishes (see code below).

I can't get this code to work with _IECreateEmbedded (_IEFormGetObjByName and _IEFormElementGetObjByName weren't returning anything), I'm guessing that's due to:

There are several properties related to an InternetExplorer object (e.g. returned by _IECreate) that do not apply to this object. These include status text, addressbar and others that may exist for a browser, but do not exist for an embedded control.

Granted, that's a bit vague, so I'm not really sure. Does anybody have any suggestions for making this happen in the background, without any windows flashing in front of the user?

Is there some magical way to truly hide an _IECreate object, or can somebody show me a working example with IECreateEmbedded?

#include <IE.au3>; browser
$path = 'c:\log.txt'
$url = 'http://www.removed.com/g.html'

; CREATE BROWSER
$oIE = _IECreate($url)

; get the form
$oForm = _IEFormGetObjByName($oIE, 'ding')

; get the file input box.
$file = _IEFormElementGetObjByName($oForm, "file")

; get the 'handle' (hwnd) for the IE window.
$hIE = _IEPropertyGet($oIE, "hwnd"); 

; Assign input focus to the field and then send the text string
_IEAction($file, "focus")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $path)

_IEFormSubmit($oForm)
Link to comment
Share on other sites

I don't see anything in your example where you are trying to make anything invisible. You can do this by using the $f_visible parmeter of _IECreate.

Consider this example... how does it differ from what you are trying to do?

#include <IE.au3>
$oIE = _IE_Example("form")
_IEAction($oIE, "invisible")
$oFile = _IEGetObjByName($oIE, "fileExample")
$hIE = _IEPropertyGet($oIE, "hwnd")
_IEAction($oFile, "focus")
$hIE = _IEPropertyGet($oIE, "hwnd")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "test.txt")
Sleep(6000)
_IEAction($oIE, "visible")

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

I deleted the _IEAction($oIE, "invisible"), and forgot to put it back. The window shows up for a second, and _then_ it becomes 'invisible', which is not what I wanted.

Here's a failed attempt to do the same thing using _IECreateEmbedded, but when you run it, $oForm, and $oFile are empty, and so is the input box.

#include <IE.au3>
#include <GUIConstants.au3>; GUI

Opt('GUIOnEventMode' , 1); Change to OnEvent mode

_IEErrorHandlerRegister()
$oIE = _IECreateEmbedded()

$oWin = GUICreate('Temp IE Window', 700, 620, _
  (@DesktopWidth - 700) / 2, (@DesktopHeight - 620) / 2, _
  $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS)


GUISetOnEvent($GUI_EVENT_CLOSE, 'CloseWin')

$GUIActiveX = GUICtrlCreateObj($oIE, 10, 50, 680, 560)

_IENavigate($oIE, @ScriptDir & "\invisible.htm")

; get the form
$oForm = _IEFormGetObjByName($oIE, 'fileform')

If $oForm Then msgbox(0,'', $oForm)

; get the file input box.
$oFile = _IEFormElementGetObjByName($oForm, 'fileinput')

If $oFile Then msgbox(0,'', $oFile)

; get the 'handle' (hwnd) for the IE window.
$hIE = _IEPropertyGet($oIE, "hwnd");

; Assign input focus to the field and then send the text string
_IEAction($oFile, "focus")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "test.txt")
; _IEFormSubmit($oForm)

Sleep(6000)
msgbox(0,'', 'Waking up')
GUISetState(@SW_SHOW, $oWin)

; stay here until you close it.
While 1
WEnd

Func CloseWin()
  Exit
EndFunc

Edit: Forgot to include source for 'invisible.html':

<html>
<body>
<form action="#" method="post" enctype="multipart/form-data" name="fileform">
<input type="file" name="file" id="fileinput" value=""/>
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
Edited by aGorilla
Link to comment
Share on other sites

So, did you try the $f_visible parameter to _IECreate ?

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

Not until just now. Worked like a charm. Thanks much!

I think I only saw the '_IEAction($oIE, "invisible")' in your post above, because that's what you used in the code. Didn't even know that was an option, because I've mostly been using the embedded form (hey, I've only been doing this for 8 days, I'm hardly an expert).

Working example (using the same html as my original post):

#include <IE.au3>; browser
; create browser
$oIE = _IECreate(@ScriptDir & "\invisible.htm", 0, 0)

; get the form
$oForm = _IEFormGetObjByName($oIE, 'fileform')

; get the file input box.
$oFile = _IEFormElementGetObjByName($oForm, "fileinput")

; get the 'handle' (hwnd) for the IE window.
$hIE = _IEPropertyGet($oIE, "hwnd");

; Assign input focus to the field and then send the text string
_IEAction($oFile, "focus")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", @ScriptDir & '\test.txt')

; delete these - just used for testing.
msgbox(0, '', _IEFormElementGetValue ($oFile))
_IEAction($oIE, "visible") 

;_IEFormSubmit($oForm); uncomment this after testing.
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...