Jump to content
XinYoung

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. 

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.

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)
            WinActivate($hChoose)
            Send($finalFile)

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")
Sleep(2000)
Send("Hello?")
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

  • Similar Content

    • By yffulf
      Is there probably a way to click ie popup button and hide or invisible popup button in the same time?
      I try to use WinSetState @SW_hide ,
      the result is ie crashing or no response because button hide and the next click command won't work...
      $oForm=_IEFormGetObjByName($oIE,"form1") $obutton=_IEFormElementGetObjByName($oForm,"btn_OK") $hWnd = _IEPropertyGet($oIE, "hwnd") _IEAction($obutton,"focus") ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") WinWait("", "確定存檔嗎?") WinSetState("","確定存檔嗎?",@SW_Hide) ControlClick("", "確定存檔嗎?", "[CLASS:Button; TEXT:確定; Instance:1;]")  
    • By _leo_
      Hey there!
      I am having a problem with clicking a button in IE. As you can see in the code, there would be a class name to click it, but since this button exists several times with exactly the same code, I can only use the "Noch nicht veröffentlicht" to separate it from the others. But this part is just pure text without any classification. 
      "<div class="checkmark" data-v-1e5b1f70=""><svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 16 16" data-v-1e5b1f70=""><circle cx="8" cy="8" r="8" data-v-1e5b1f70="" /></svg></div>Noch nicht veröffentlicht"
      I was trying to click it with:
      #include <IE.au3> local $oNNVs = _IEFormGetCollection($oIE2) For $oNNV in $oNNVs If String($oNNV.innertext) = "Noch nicht veröffentlicht" Then _IEAction($oNNV, "click") EndIf Next and:
      $inputs = $oIE2.document.getElementsByTagName("div") For $input In $inputs If $input.innertext == "Noch nicht veröffentlicht" then $input.click() EndIf Next But nothing seems to work. Thanks for the help!
    • By rudi
      Hi,
      from other postings here as a start I'm quite Close to my Goal of putting formatted text to the clipboard:
      #include-once #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_idLblMsg, $g_hRichEdit Example("The first text will be formatted ""as is""" & @CRLF & _ "(Default Font and font size)", "This text is formatted differently") MsgBox(0, "Rich Text copied", "Formatted Text put to clipboard") Func Example($TextDefault, $TextCourier) Local $hGui, $iMsg, $idBtnNext, $iStep = 0 $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) $g_hRichEdit = _GUICtrlRichEdit_Create($hGui, $TextDefault, 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetSel($g_hRichEdit, -1, -1) ; set selection behind last CHAR in RTF_EDIT _GUICtrlRichEdit_SetFont($g_hRichEdit, 8, "Courier New") ; change font to 8pt, Courier New _GUICtrlRichEdit_AppendText($g_hRichEdit, @CRLF & $TextCourier) _GUICtrlRichEdit_SetSel($g_hRichEdit, 0, -1) ; select all the content of the RTF_EDIT _GUICtrlRichEdit_Copy($g_hRichEdit) ; put the selection to the clipboard EndFunc ;==>Example  
      Finally the clipboard content has to hold pre-formatted data to be pasted into an email body. for the 2nd part I'd like to add a frame around the text, like I did manually before taking this screenshot.



      Any suggestions, or maybe some absolutely different Approach?
       
      CU, Rudi.
    • By TXTechie
      Hello Everyone,
      I'm looking for a way to use an already open Internet Explorer (IE) window (if one is up and running) and then navigate to a new URL in a new IE tab.
      I thought that _IECreate would easily meet my needs. However, when I use the following script:
      #include <IE.au3> Local $oIE = _IECreate("https://" & $Server & ":8444/", 1, 1, 0, 1) ...with one or more open IE windows, it still opens yet a new IE window.
      Are there any other ideas for how to reliably use an already open IE windows and then how to open a new tab in IE to navigate to a new URL?
      Regards,
      TX Techie
    • By WoodGrain
      Hi All,
      I've tried to create a script to browse to a web page in IE, but it only works for some sites, I've tried to simplify the script as much as possible, hoping you can point me in the right direction - thanks.
      This one going to Google does work:
      #include <IE.au3> $oIE = _IECreate("https://www.google.com.au/", 0, 1, 1) _IELoadWait($oIE) _IEQuit($oIE) But this one going to OneDrive opens the IE page, but fails immediately returning the errors, and the IE window is not closed:
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147023174, Browser has been deleted prior to operation.)
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidObjectType ()
      --> IE.au3 T3.0-2 Error from function _IEQuit, $_IESTATUS_InvalidObjectType
      #include <IE.au3> $oIE = _IECreate("https://abccorp-my.sharepoint.com/", 0, 1, 1) _IELoadWait($oIE) _IEQuit($oIE) Even if I put a sleep timer in for 10 seconds after the _IECreate it still doesn't work
      Thanks all!
×
×
  • Create New...