Jump to content

Recommended Posts

Posted

Hello all! :bye:  I'm stuck at a seemingly simple part of my script. Using IE, I'm filling out a web form that involves clicking a "Browse" button and selecting a file. Once the file explorer dialog opens, however, I am unable to control it.

I have a string, which is the name of the file I want, and I'm trying to insert it into the 'File name:' text box in the dialog (which already has focus), but it doesn't get inserted. I've tried ClipPut and Send. 

image.png.037b5c3dd7fff032ed29f16480e3fb5c.png

What's even more concerning is, when I close the dialog, the string is then pasted into the very next window that has focus, which is often SciTE. It's like that Browse's file open dialog halts all processes. Once it's closed, the script continues.

;~  Open a IE window and navigate to the login page.
            Global $oIE = _IECreate($urlBBLogin)
            _IELoadWait($oIE)

;~  Recognize the form on this page (login input boxes).
            Local $oForm = _IEFormGetObjByName($oIE, "login")
            Local $oTextLogin = _IEFormElementGetObjByName($oForm, "user_id")
            Local $oTextPass = _IEFormElementGetObjByName($oForm, "password")

;~  Enter the Automation user credentials into the form.
            _IEFormElementSetValue($oTextLogin, $bbUsername)
            _IEFormElementSetValue($oTextPass, $bbPassword)

;~  Click the Login button.
            _IEFormSubmit($oForm)
            _IELoadWait($oIE)

;~ Navigate to the feedfile upload page.
            _IENavigate($oIE, $urlUpload)
            _IELoadWait($oIE)

;~ Click the Browse button
            Local $Browse = _IEGetObjById($oIE, "feedFile_chooseLocalFile")
            _IEAction($Browse, "Click")
            Local $Browse = WinWait("Choose File to Upload")
            
;~ Open the file we created.
            WinActivate($Browse)
            Send($finalFile)

Has anyone else experienced this problem? Any ideas to get around it? Am I approaching this the wrong way?

Any support is greatly appreciated.

Thank you.

Posted
3 hours ago, Danp2 said:

Have you tried the forum search feature? This particular topic has been covered in the past.

I can't find anything relevant.

Posted

Ok, I'm able to get the handle of the dialog but the script still hangs while the dialog is open. It only continues once it's closed.

For example, the msgbox won't appear until the dialog is closed, so i'm still unable to proceed.

;~ Click the Browse button
            Local $Browse = _IEGetObjById($oIE, "feedFile_chooseLocalFile")
            _IEAction($Browse, "Click")

;~ In the FileOpenDialog, open the file we created.
            $hChoose = WinGetHandle("Choose File to Upload")
            MsgBox($MB_SYSTEMMODAL, "", $hChoose)
            WinActivate($hChoose)
            Send($finalFile)

I can't find anything that resolves the script hanging while the dialog is open.

Posted
1 hour ago, Danp2 said:

Take a look at the 2nd example for _IEAction in the help file.

That example presses a Submit button then closes a pop up. It doesn't interact with a FileOpenDialog window....

I tried modifying it to make it applicable, but I still can't send anything to the "Choose File to Upload" window. And again, when I close the window, the script continues because everything stops once the FileOpenDialog is opened.

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oBrowse = _IEGetObjByName($oIE, "fileExample")
Local $hWnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($oBrowse, "focus")
_IEAction($oBrowse, "Click")
;~ ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "Click")

; Wait for Alert window, then click on OK
WinWait("", "Choose File to Upload")
Sleep(2000)
Send("Hello?")
ControlClick("", "Choose File to Upload", "[CLASS:Button; TEXT:Cancel; Instance:1;]")

 

Posted

OHHH so all I have to do to avoid the hanging is to not click the "Browse" button, but instead, focus it and send an Enter.

That makes no sense, but OK! It does seem to work.

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
×
×
  • Create New...