Jump to content

Can't get focus on a file open dialogue box

Recommended Posts

Can anyone help with this little problem.  I'm opening IE to a local website and trying to select a file to upload.  See the script below:

#include <ie.au3>

$oIE = _IECreate("")

Local $oForms = _IEFormGetCollection($oIE)
$oForm = _IEFormGetObjByName($oIE, "loginForm")
$oUsername = _IEFormElementGetObjByName($oForm, "username")
$oPassword = _IEFormElementGetObjByName($oForm, "password")
_IEFormElementSetValue($oUsername, "#######", 1)
_IEFormElementSetValue($oPassword, "#######", 1)
$oLogin = _IEFormElementGetObjByName($oForm, "login")
_IEAction($oLogin, "click")

_IELinkClickByIndex($oIE, 3)
Local $oForms = _IEFormGetCollection($oIE)
$oForm = _IEFormGetObjByName($oIE, "install")
$oFileLocation = _IEFormElementGetObjByName($oForm, "File")
_IEAction($oFileLocation, "click")

WinWaitActive("Choose File to Upload")

ControlSetText("Choose File to Upload", "", "Edit1", "C:\test.txt")

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

The code works, but I have a problem with everything that happens after the "file" "click".  At this point the "Choose File to Upload" dialogue box will open but nothing else executes.  If I manually close the dialogue box and manually click "File" the code will then execute ie select my file ready for upload.

Any ideas?

Thanks in advance.


Link to post
Share on other sites

Call a second script that will interact with the window, just prior to click that opens it...or, call a second script to perform the actual click.

I think you are also able to focus, and use a controlsend {Enter}, and you won't be deadlocked on the window.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to post
Share on other sites

Thanks for your reply.  I'd rather keep everything in one script if I can as it should be easier send out if I need others to use it.  I've tried using a function and calling the function just before and after the click event but I still have the same problem.

As regards using focus and controlsend, doesn't controlclick or controlsettext work in the same way?  I'm a bit of a newbie so I don't understand the subtleties.  As mentioned, the code does work but only after closing the upload file dialogue and reopening it.  It's as if the process can't find the open window the first time around.

Thanks again

Link to post
Share on other sites

Try this for see debuginfos :

$hWnd = WinWait("Choose File to Upload", 5 )
ConsoleWrite ( '$hWnd : ' & $hWnd & @CRLF )
$Ret = ControlSetText($hWnd, "", "Edit1", "C:\test.txt")
ConsoleWrite ( 'ControlSetText : ' & $Ret & @CRLF )
$Ret = ControlClick($hWnd, "", "Button1")
ConsoleWrite ( 'ControlClick : ' & $Ret & @CRLF )
Edited by wakillon

AutoIt X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...