Jump to content

Upload photo to website form


darkyr
 Share

Recommended Posts

$oForm=_IEFormGetObjByName($oIE, "uploadfile")
$oInputFile=_IEFormElementGetObjByName($oForm, "photo_upload")
_IEAction($oInputFile, "click")
WinWait("Choose File to Upload")
$hChoose = WinGetHandle("Choose File to Upload")
ControlSetText($hChoose, "", "Edit1", "C:\AUTOEXEC.BAT")
ControlClick($hChoose, "", "Button2")

The internet explorer "choose file to upload" pops up but after that the functions don't set the text nor do they click the button.

Could somebody take a look and tell me if I'm missing something?

Link to comment
Share on other sites

$oForm=_IEFormGetObjByName($oIE, "uploadfile")
$oInputFile=_IEFormElementGetObjByName($oForm, "photo_upload")
_IEAction($oInputFile, "click")
WinWait("Choose File to Upload")
$hChoose = WinGetHandle("Choose File to Upload")
ControlSetText($hChoose, "", "Edit1", "C:\AUTOEXEC.BAT")
ControlClick($hChoose, "", "Button2")

The internet explorer "choose file to upload" pops up but after that the functions don't set the text nor do they click the button.

Could somebody take a look and tell me if I'm missing something?

Try

$oForm=_IEFormGetObjByName($oIE, "uploadfile")
$oInputFile=_IEFormElementGetObjByName($oForm, "photo_upload")
_IEAction($oInputFile, "click")
$Window = WinWait("Choose File to Upload")
ControlSetText($Window, "", "Edit1", "File here")
ControlClick($Window, "", "Button2")

Also, C:\Autoexec.bat != photo

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Try

$oForm=_IEFormGetObjByName($oIE, "uploadfile")
$oInputFile=_IEFormElementGetObjByName($oForm, "photo_upload")
_IEAction($oInputFile, "click")
$Window = WinWait("Choose File to Upload")
$1 = ControlSetText($Window, "", "Edit1", "File here")
If $1 = 0 Then Msgbox(0x0, "Error", "Failed at $1")
$2 = ControlClick($Window, "", "Button2")
If $2 = 0 Then Msgbox(0x0, "Error", "Failed at $2")

It should tell you where it's failing.

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

thank you, i got it to work, it seemed the problem was that it didnt finish loading the last page so the script didn't go forward, it just needed a _IeloadWait() .. i kinda feel stupid now

$Window = WinWait("Choose File to Upload")
ControlSetText($Window, "", "Edit1", "File here")
ControlClick($Window, "", "Button2")

but this works perfectly, thanks again !

Edited by darkyr
Link to comment
Share on other sites

actually it seems it doesnt work until i click the browse button myself then it proceeds to fill and submit, does anybody know why doesnt it pick up the _IeAction popup window and only picksup the mouse click one?

MouseMove(_IEPropertyGet($oInputFile, "screenx") + _IEPropertyGet($oInputFile, "width") - 10, _
          _IEPropertyGet($oInputFile, "screeny") + _IEPropertyGet($oInputFile, "height")/2)
MouseClick("left")
$Window = WinWait("Choose File to Upload","",5)
ControlSetText($Window, "", "Edit1", "File here")
ControlClick($Window, "", "Button2")

found dale's example to work but its still interesting if somebody could explain why the IeAction popup doesn't get catched by winwait, thanks!

Edited by darkyr
Link to comment
Share on other sites

  • 4 months later...

When you click the button using the DOM, control does not return to your script until the dialog has been processed. Usint the mouse-click avoids this since control returns to you immediately after the click is processed.

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

So Dale, it seems if I want to avoid keyboard interruption, ie not using a mouseclick, the only approach appears to be to use IEACTION to select the button, and kick off a second process that can complete and close the input box, so processing can effectively be done in the background - would you agree?

Link to comment
Share on other sites

No, I don't agree. Use the code in @darkyr's last reply - it came from the examples I write and you'll find in my sig.

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

his last example was

MouseMove(_IEPropertyGet($oInputFile, "screenx") + _IEPropertyGet($oInputFile, "width") - 10, _
          _IEPropertyGet($oInputFile, "screeny") + _IEPropertyGet($oInputFile, "height")/2)
MouseClick("left")
$Window = WinWait("Choose File to Upload","",5)
ControlSetText($Window, "", "Edit1", "File here")
ControlClick($Window, "", "Button2")

which requires a mousemove/click - which is what I'm trying to avoid...

Link to comment
Share on other sites

My sig contains two examples. Look at them.

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

the first example is the same as above Dale

#include <IE.au3> $oIE = _IE_Example("form") $oT = _IEGetObjById($oIE, 'fileExample') MouseMove(_IEPropertyGet($oT, "screenx") + _IEPropertyGet($oT, "width") - 10, _          _IEPropertyGet($oT, "screeny") + _IEPropertyGet($oT, "height")/2) MouseClick("left") WinWait("Choose File to Upload") $hChoose = WinGetHandle("Choose File to Upload") ControlSetText($hChoose, "", "Edit1", "C:AUTOEXEC.BAT") ControlClick($hChoose, "", "Button2")

and I'm not sure which is the second example from all of the links... could you point the obvious out for me please?

Link to comment
Share on other sites

  • 2 weeks later...

It's strange that when I call an external program to complete an input box selected in IE via IEACTION($oIE, "clieck") it works fine but when I do the same via an adlibregister function it does not...

Func UploadPic()

If WinExists("Choose File") Then

ControlSetText("Choose File to Upload", "", "[CLASS:Edit; INSTANCE:1]", $photo)

Sleep(1000)

ControlClick("Choose File to Upload", "", "Button1")

AdlibUnRegister("UploadPic")

EndIf

EndFunc

Edited by DelStone
Link to comment
Share on other sites

and I'm not sure which is the second example from all of the links... could you point the obvious out for me please?

Automate input type=file

Those are two links from my sig with slightly different implementations.

Control is not returned to your script, AdLib functions can't run either. Look at the two examples.

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

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

×
×
  • Create New...