Jump to content
Sign in to follow this  
darkyr

Upload photo to website form

Recommended Posts

darkyr

$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?

Share this post


Link to post
Share on other sites
rcmaehl

$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

  • Like 1

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
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites
darkyr

still didn't work and C:\Autoexec.bat was from an example i found in the forums, thanks for replying

Share this post


Link to post
Share on other sites
rcmaehl

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.

  • Like 1

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
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Share this post


Link to post
Share on other sites
darkyr

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

Share this post


Link to post
Share on other sites
darkyr

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

Share this post


Link to post
Share on other sites
DelStone

I too would be interested in knowing why this is the case...

Share this post


Link to post
Share on other sites
DaleHohm

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

  • Like 1

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
DelStone

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?

Share this post


Link to post
Share on other sites
DaleHohm

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

Share this post


Link to post
Share on other sites
DelStone

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

Share this post


Link to post
Share on other sites
DaleHohm

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

Share this post


Link to post
Share on other sites
DelStone

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?

Share this post


Link to post
Share on other sites
DelStone

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

Share this post


Link to post
Share on other sites
DaleHohm

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

Share this post


Link to post
Share on other sites
DelStone

Thanks Dale - problem solved :oops:

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  

  • Similar Content

    • Nareshm
      By Nareshm
      Its Possible To auto Login with autoit script ?
    • ur
      By ur
      I saw few UDFs related to IE and Firefox to automate tasks related to these browsers.
       
      But is it possible to automate tasks like drag and drop in the website.?
      Like in the below video.
      If not can you tell me some alternatives, as it is not possible in selenium as I heard.
      drag_and_drop.mp4
    • AnonymousX
      By AnonymousX
      Hello,
      I need to pull data from company intranet website. I created a script that I can give a list of project numbers and it will open up the the related webpage for each project, save the html comments for that project, then move on to the next. 
      However my problem comes in that each time I open up a project it locks it for other users, and if you just exit the page it keeps it locked, you have to actually press the "close" button on the page. So I'm not sure how to deal with this as I end up just locking every project in my name when I run my program as I don't understand the nature of how the website is built. I don't understand how to close with just using my automation code without manually having to press the stupid button. 
      My Function:
      Func Getscript($ProjectAddress) ;getting the page source code and storing it into text file for easy reading it $file = FileOpen(@ScriptDir & "\source.txt", 10) $IE = _IECreate($ProjectAddress & ".html", 0, 0) $source = _IEDocReadHTML($IE) FileWrite($file, $source) $target_source = _StringBetween($source, "<BODY>", "</BODY>") ; only take content between the specified tags _IEQuit($IE) FileClose($file) return $target_source[0] EndFunc ;==>Getscript  
      Source Code I got from website that I think is relevant:
      function closeForm(){ if(topButtonEnabled("closeButton")){ parent.mainFrame.closeForm(); } } <button id="closeButton" class="saveCloseButton" style="LEFT: 77px;" onclick=closeForm()>&nbsp;Close&nbsp;</button>  
      Any Ideas of how to tell website to either activate the closeform function or just give it the command to close?
       
      Thanks
    • Pintu
      By Pintu
      Good evening guys,
      i'm having a problem, not about the code (i'm only thinking about it at the moment) but about the way i can do it.
      I have a webpage (photo N.1) it has some elements in it.
      I need only the table (photo N.2), looking at the code and with _IEFunctions i can easy find the table but how i can i "copy" it?
      As i said it's really easy to found with a script but what should i do then? Copy the source? And how can i display it to the user?
      In my head i'd like to display it inside a GUI, is that possible?
       
      Thanks in advance
       
      Edit: Posted 2 times same photo. Now should be OK

       

    • ruslanas402
      By ruslanas402
      Greeting, so I've been trying to come up with solution, but no luck. Despite I tried to automate upload function, I released that it freezes after "Choose File to Upload" window appears..
       
      #include <IE.au3> ;#include <_Dbug.au3> Global $oIE = _IECreate("http://tinypic.com/", 1) Global $upload2 = _IEGetObjById($oIE, "the_file") _IEAction($upload2, "click") ;Sleep(1000) $hWnd = WinGetHandle("Choose File to Upload") MsgBox(0, "", $hWnd) Have anybody faced this situation?
      btw: srry for the advertise Besides it's no matter which site I'm trying to do this it's all the same.
×