Sign in to follow this  
Followers 0
darkyr

Upload photo to website form

16 posts in this topic

$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



$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

1 person likes this

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


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

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

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.

1 person likes this

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


Active: IRC UDF, WindowEx UDF
Discontinued: GithubBubbleSort UDF

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

#6 ·  Posted (edited)

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

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

Share this post


Link to post
Share on other sites

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

1 person likes this

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

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

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

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

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

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

#14 ·  Posted (edited)

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

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

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  
Followers 0

  • Similar Content

    • 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.
    • RyukShini
      By RyukShini
      Hello everyone!

      I am trying to make a script that uploads files for me in wordpress(All I need to do is to manually choose which files to upload)
      Here is my script so far:
       
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> Upload() Func Upload() $sPD = "log=username&pwd=mypassword&wp-submit=Log+ind&redirect_to=http%3A%2F%2Fmyurl.com%2Fwp-admin%2F&testcookie=1" oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "http://myurl.com/wp-login.php " & $sUSR, False) ; Post url $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") $oHTTP.SetRequestHeader("Accept-Language", "en-US,en;q=0.5") $oHTTP.SetRequestHeader("User-Agent", "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.52 YaBrowser/15.12.2490.3614 (beta) Yowser/2.5 Safari/537.36") $oHTTP.SetRequestHeader("Referer", "http://myurl.com/wp-login.php?redirect_to=http%3A%2F%2Fmyurl.com%2Fwp-admin%2F&reauth=1") $oHTTP.SetRequestHeader("Cookie", "wordpress_test_cookie=WP+Cookie+check") $oHTTP.SetRequestHeader("Connection", "keep-alive") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") ; Header data > $oHTTP.Send($sPD) $oHTTP.Open("GET", "http://myurl.com/wp-admin/media-new.php", False) ; Post url $oHTTP.SetRequestHeader("Host", "myurl.com") $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0") $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") $oHTTP.SetRequestHeader("Accept-Language", "en-US,en;q=0.5") $oHTTP.SetRequestHeader("Referer", "http://myurl.com/wp-admin/") $oHTTP.Send() Endfunc The upload button = "Choose Files"
      Example code from:
      https://www.autoitscript.com/autoit3/docs/functions/FileOpenDialog.htm
      #include <FileConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() ; Create a constant variable in Local scope of the message to display in FileOpenDialog. Local Const $sMessage = "Select a single file of any type." ; Display an open dialog to select a file. Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST) If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file was selected.") ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) Else ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder. FileChangeDir(@ScriptDir) ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog. $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF) ; Display the selected file. MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog) EndIf EndFunc ;==>Example The HTML:
       
      <p class="drag-drop-buttons"><input style="position: relative; z-index: 1;" id="plupload-browse-button" value="Choose Files" class="button" type="button"></p> Some header info in the HTTP request:
       
      POST http://myurl.com/wp-admin/async-upload.php HTTP/1.1 Host: myurl.com User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://myurl.com/wp-admin/media-new.php Content-Length: 4555551 Content-Type: multipart/form-data; boundary=---------------------------12345678910 Cookie: LONG COOKIE HERE! DNT: 1 Connection: keep-alive -----------------------------102062144610664 Content-Disposition: form-data; name="name" hdfhfg.jpg -----------------------------102062144610664 Content-Disposition: form-data; name="post_id" 0 -----------------------------102062144610664 Content-Disposition: form-data; name="_wpnonce" 123456 -----------------------------102062144610664 Content-Disposition: form-data; name="type" -----------------------------102062144610664 Content-Disposition: form-data; name="tab" -----------------------------102062144610664 Content-Disposition: form-data; name="short" 1 -----------------------------102062144610664 Content-Disposition: form-data; name="async-upload"; filename="hdfhfg.jpg" Content-Type: image/jpeg This wouldn't be much of a problem if I just had some simple post data, but this makes my head spin....
      Thanks in advance Masters!
      (I could probably easily do this with IE, but I'd rather not use IE, I am not a big fan of it)