Jump to content
Sign in to follow this  

Web form's "Browse" button opens a file open dialog I cannot control

Recommended Posts

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. 


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)

;~  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.

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

;~ 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.

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.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

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)

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

Share this post

Link to post
Share on other sites
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")
ControlClick("", "Choose File to Upload", "[CLASS:Button; TEXT:Cancel; Instance:1;]")


Share this post

Link to post
Share on other sites

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.

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 FUD
      please i need help 
      i need to open link in default browser only one windows without duplicate if i try to open the same link 
    • By Fadi
      Hi i'm trying to create a ClipPut with differents font size and font and then paste it into word document.
      I know in Word document, i can send("^+P") and change the font size, but it's not then best way to do if i have to change the font and size many time in the document.
          WinActivate("ReportTemplate.doc [Compatibility Mode] - Word")
          WinWaitActive("ReportTemplate.doc [Compatibility Mode] - Word")
          Sleep (1000)
          ClipPut("Underline Size 16: " & "Bold size 12" & "Normcal size 11")
      Any idea?
    • By diff
      still learning and trying to understand AutoIT but having problem in filling my PDF file.
      So my code looks like similar to this:
      Global $1 = "text text 44444444" Global $2 = "texting2 texting2" Global $3 = "newtext3 next3" ShellExecute ("C:\Users\XXX\Desktop\myPDF.pdf") WinWaitActive("MyPDF.pdf - Adobe Acrobat Reader DC") Send ("{TAB}") ClipPut($1) Send ("^v") Send ("{TAB 3}") ClipPut($2) Send("^v") Send ("{TAB}") ClipPut($3) Send("^v") So its fill my PDF form, the first field looks good, the code add the text text 4444, then second should be $2 with texting2 texting2 but for some reason the code uses for second and third field after TAB only variable $3.
      So, I receive in $2 and $3 for some reason same newtext3 next3 in both, why its skipping the variable $2? Maybe there also much better solution for instant text? Because Send writes with delay by letters which I don't like.
    • By Mariog2000
      I've tried for a few days to simply open a url in IE and click an IE object that I can't "TAB" to and don't want to use a mouse-click if at all possible.  I've read up on things like using IEAction and IETagNameGetCollection to find the object but not smart enough to figure out how that works with my url or how to tell if my url is "basic" or a "form", "frameset", "iframe", etc.
      The other problem is I've tried using the "Run" and "ShellExecute" commands to open the browser, which works, but it opens it in a way that doesn't include my currently logged in user account.  For example, if I just click IE or Chrome for that matter and open my default homepage of google, the page that opens knows I'm logged in.  When I use "Send" "ShellExecute" or "_IE_Create" they always open pages generically which would require a login.
      So questions are, if I have a URL I'm trying to open, that's passes the currently logged on users credentials when opening the page (no clue where that happens)
      1.  Are there any code examples someone is willing to share that opens my IE maximized, with logged in credentials, and
      2.  Once that works, can someone suggest a technique a non-developer can find which IE Objects I need to send a "click" to so it opens the correct menu, pop-up, url, etc., associated with that object.  I've copied what doesn't work and sure I'm way off but it's not for a lack of effort. I'll keep trying and post updates but not looking good 🙂
      #include <IE.au3>
      Call ("selection")
      Func selection ()
      Global $oIE = _IECreate ("https://internal-webpage.aspx")
      Local $selectid = _IEGetObjByName ($oIE, "signageNo")
      Local $button = _IEGetObjByName ($oIE, "GO")

      _IEFormElementOptionSelect ($selectid, "3")
      _IEAction ($button,"click")
      #include <IE.au3> Call ("selection") Func selection () Global $oIE = _IECreate ("https://internal-webpage.aspx") Local $selectid = _IEGetObjByName ($oIE, "signageNo") Local $button = _IEGetObjByName ($oIE, "GO") _IEFormElementOptionSelect ($selectid, "3") _IEAction ($button,"click") EndFunc 1. 
  • Create New...