Sign in to follow this  
Followers 0
jens14

Can't get focus on a file open dialogue box

4 posts in this topic

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("http://127.0.0.1.etc.etc")
_IELoadWait($oIE)

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")
_IELoadWait($oIE)

_IELinkClickByIndex($oIE, 3)
_IELoadWait($oIE)
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.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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.

Share this post


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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