Jump to content

Type Filepath and Name at file select window


Recommended Posts

Capture.jpg

This is the file select window I see when I visit a certain website and clicks on a "File Upload" button. I want to be able to automate this so it automatically select files itself. For example, select a file from the desktop named "1.jpg" then clicks the "Open" button to select the file and close the window. How can I achieve this? I tried using AU3Record but it doesn't seem to record this section. I think the main goal here is to be able to type the file path and name in the "File name:" box then click "Open". I am using IE.AU3 to get to this website by the way. Please advise. I do not and cannot use my own fileopen dialogue box.

Link to comment
Share on other sites

It seems that you are using Internet Explorer.

So you can try something like this :

#include <IE.au3>

$oIE = _IE_Example("form")
$oT = _IEGetObjByName($oIE, 'fileExample')

_IEAction($oT, "focus")
ControlSend( _IEPropertyGet($oIE, "hwnd"), "", "", "{SPACE}" )

$hChoose = WinWait("Choose File to Upload")

ControlSetText($hChoose, "", "Edit1", @ScriptFullPath)
; ControlClick($hChoose, "", "Button1")
ControlClick($hChoose, "", "[TEXT:&Open]") ; or try with [TEXT:Open] because i'm not sure about the "&", because the O of the Open button is not underlined in your screen capture
Edited by jguinch
Link to comment
Share on other sites

 

It seems that you are using Internet Explorer.

So you can try something like this :

#include <IE.au3>

$oIE = _IE_Example("form")
$oT = _IEGetObjByName($oIE, 'fileExample')

_IEAction($oT, "focus")
ControlSend( _IEPropertyGet($oIE, "hwnd"), "", "", "{SPACE}" )

$hChoose = WinWait("Choose File to Upload")

ControlSetText($hChoose, "", "Edit1", @ScriptFullPath)
ControlClick($hChoose, "", "Button1")

This seem to be for a sample file select dialogue. It doesn't seem to work. I'm not sure where that file select window came from, if it's the window of IE itself. All I know is if I visit that webpage to click Upload, that window shows up. I do not know the name of its controls so I do not know how to run a script for it.

Link to comment
Share on other sites

It doesn't work on that window, the AU3 Record doesn't even record anything when clicking or doing any actions on that window. I have found a temporary solution though, just beside the UPLOAD button there's actually a textbox that will contain the file path of the file you selected, so I skipped the UPLOAD button and just went to coding a file path in that texbox. Thanks guys, I hope I will never come across writing scripts that involves those windows again.

Link to comment
Share on other sites

My code works for me. But my OS and/or IE are not in the same version than yours (and also are in French)

I edited my code (last line) : can you try it ?

Edited by jguinch
Link to comment
Share on other sites

Just FYI

I had a look at your situation and have come to the conclusion that you probably have your Autoit Window tool stuck on freeze( CTRL ALT F).

It also takes a couple of seconds sometimes to  load the info...

post-56351-0-43847700-1425831541_thumb.j

Bill

Link to comment
Share on other sites

Here are my last attempts. I just couldn't get Autoit to click that Browse button using Mouseclick. I can get Autoit to click the browse button using the $oT.click but then the rest of the scripts don't run, as soon as the window for File Open appears autoit freezes the rest of the codes, no errors. 
 
;$oIE.document.forms(0).elements(2).click ;This clicks the browse button but doesn't trigger the next codes. As soon as the file open window appears Autoit freezes. One thing I noticed is if I call a sleep or pause then manually click the browse button then continue running Autoit it seem to work.  
 
 Local $oT = $oIE.document.forms(0).elements(2) ;This is the Browse Button (of an Input Type="file")
 Local $iScreenX = _IEPropertyGet($oT, "screenx")
 Local $iScreenY = _IEPropertyGet($oT, "screeny")
 Local $iwidth = _IEPropertyGet($oT, "width") - 10
 Local $iheight = _IEPropertyGet($oT, "height") / 2
 $iScreenX = $iScreenX + $iwidth
 $iScreenY = $iScreenY + $iheight  
 MouseMove($iScreenX,$iScreenY) ;Mousemove or Mouseclick doesn't do anything, no errors but no move or clicks
 
 ;I can't get the codes below to work because of the problems above
 WinWait("Choose File to Upload")
 $hChoose = WinGetHandle("Choose File to Upload")
 ControlSetText($hChoose, "", "Edit1", "C:UsersSLyFoxDesktoptest.jpg")
 ControlClick($hChoose, "", "Button1")
 $oIE.document.forms(0).submit() ;This is the "Finish uploading pictures" button
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...