Jump to content
Sign in to follow this  
darkyr

Upload photo to website form

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?

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


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

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

 

Share this post


Link to post
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

Share this post


Link to post
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

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


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

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jahar
      I have an AutoIT script It monitors 2 websites for content that applys to me and the services that I provide. One site is : www.Freelancer.com The other: www.PeoplePerHour.com Both sites publish new jobs on their site hourly or so. My AutoIT app, will view those sites and present new jobs to me in a grid that pops up on my screen. Lately, the app has stopped showing me any jobs from PeoplePerHour.
       
      For freelancer.com,  Inetget is giving full html but for peopleperhour, now its not coming.
      Func _CheckPPH()
          Local Static $hTimer = 0
          Local Static $hDownload = 0
          Local $aTitlesandUrls = 0
          Local Static $sTempFile = ""
          If $hTimer = 0 Then $hTimer = TimerInit()
          If $hDownload = 0 Then
              $sTempFile = _WinAPI_GetTempFileName(@TempDir)
              ConsoleWrite("Checking PPH..." & @CRLF)
              ConsoleWrite(">Downloading..." & @CRLF)
      ;~         $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
              $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD)
      ;~         Return 0
          EndIf
      ;~     Sleep(30)
      ;~     Local $isCompleted = InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
      ;~     Local $isError = InetGetInfo($hDownload, $INET_DOWNLOADERROR)
      ;~     Sleep(30)
      ;~     If TimerDiff($hTimer) > 3000 And $isError Then
      ;~         ConsoleWrite("!PPH Fail" & @CRLF)
      ;~         InetClose($hDownload)
      ;~         $hDownload = 0
      ;~         Return 0
      ;~     EndIf
      ;~     Sleep(30)
          Local $Show = 0
      ;~     If TimerDiff($hTimer) > 3000 And $isCompleted Then
          If $hDownload > 0 Then
              ConsoleWrite("+Downloaded..." & @CRLF)
              Local $sPPHHtml = FileRead($sTempFile)
              $aTitlesandUrls = _StringBetween($sPPHHtml, '"title">' & @LF, 'time>')
      ;~         _ArrayDisplay($aTitlesandUrls)
              Local $aPPH[0][4]
              Local $sTitle = ""
              Local $sUrl = ""
              Local $sID = ""
              Local $sDate = ""
              Local $iRet=0
              Sleep(30)
              For $i = 0 To UBound($aTitlesandUrls) - 1
                  $sTitle = _StringBetween($aTitlesandUrls[$i], '<a title="', '" class')
                  $sUrl = _StringBetween($aTitlesandUrls[$i], 'href="', '">')
                  $sDate = _GetDate($aTitlesandUrls[$i])
                  If IsArray($sTitle) And IsArray($sUrl) Then
                      $sID = _GetID($sUrl[0])
      ;~                 _ArrayAdd($aPPH, $sDate & "|" & $sTitle[0] & "|" & $sUrl[0] & "|" & $sID)
                      $iRet = _BuildPopupsPPH($sID, $sDate, "PPH: " & $sTitle[0], $sUrl[0])
                      If $iRet Then $Show+=1
                  EndIf
              Next
              Sleep(30)
      ;~         If $Show > 0 Then ShowLatestJobs()
      ;~         _ArrayDisplay($aPPH)
              FileDelete($sTempFile)
              InetClose($hDownload)
              $hDownload = 0
              $hTimer = 0
              Return $Show
          EndIf
          Sleep(30)
      EndFunc   ;==>_CheckPPH
    • By singh54
      Hello All,

      I am new to auto It  and coding. Have only tried few automated logging for different websites.  The login pages of the websites which I have worked on were having form name with input type as text and it seems straight forward to automate their login using "_IEFormElementSetValue".
      I have got a url, it does not have any form in the source page. On further analyzing I found that It does call some login page separately as below.
      function showLogin(arg) {
        Global.pollingDialogDoc = null;
        var fresh = jQuery.isValidString(arg) && "fresh" == arg ? !0 : !1, appFrame = $("#appFrame");
        if ($("#modalFrame").show(), $("iframe").hide(), fresh || !appFrame.attr('src').match("html/login.html")) appFrame.attr('src', baseURL + 'html/login.html'), 
        appFrame.on('load', function() {
          setTimeout(function() {
            $("#modalFrame").hide(), appFrame.show();
          }, 1);
        }); else try {
          window.frames.appFrame.updatePageFromIndex();
        } catch (e) {}
      }
      I can simply use "send" and "mouse click" Method to automate the login but that doesn't seems very reliable. Is there any separate way to fill the user ID and password to the respective fields by having reference by frames or something. 
      Appreciate if any one can point me to correct document or help in any way...!
    • By kingjacob90
      Hay guys
      Just had an idea and wanted to know where to start. I want to download a screenshot of a website automatically into a .png .jpg ect format so I can then set it as my desktop background.
      This might be for for news: When the latest news is added to a website a screenshot of that website is saved and added to my desktop background.
      I have tried using website that already do the screenshot but you have to open the website and click the button for it to generate one and thus InetGet does not help.
      Any Ideas?
    • By naru
      Its Possible To auto Login with autoit script ?
    • 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
×
×
  • Create New...