Jump to content
Sign in to follow this  
corgano

Get file select window associated with $oIE

Recommended Posts

corgano

I have been working with internet explorer to upload files to a private database using a web forum. Like many IE projects do, I eventually ran into the good ol' file select dialog. After finding a way to open the dialog, I ran into the issue of making sure the dialog belongs to my $oIE instead of another IE window. With a bit of searching, I came up with a solution which works brilliantly!....

Func _IE_GetFileSelectWindow($oIE)
        ;Get IE handle
    Local $hIE = _IEPropertyGet($oIE, "hwnd"), $errors = 0
        
        ;Go through every instance of upload window
    for $i = 1 to 99999
                ;Get it's handle, call it child
        $child = WinGetHandle("[TITLE:Choose File to Upload; CLASS:#32770; INSTANCE:"&$i&"]","")
        ;Check for running out of windows
                if @error Then
            $errors += 1
            If $errors = 4 Then Return 0
        EndIf

                ;Get the child's parent
        $parent = _WinAPI_GetParent($child)
        ConsoleWrite("IE: "&$hIE&"  Child: "&$child&"   Parent: "&$parent&@CRLF)
        ;Check if $hIE and the parent are the same. This should work, the download window should be the
                ;child of $hIE so this should work,  and does on XP and older versions of IE
                ;but does not on IE 10
                If $parent = $hIE Then Return $child
    Next
    Return 0
EndFunc

.....on windows XP. On windows seven the IE handle is not the same as the file select dialogue's parent window :/ I assume this has something to do with how the new IE handles tabs. Has anyone else had this issue? Does anyone know of a workaround? Running IE 10

Moar info!

IE: 0x006B05C0

Child: 0x00381868

Child's parent: 0x00A0014A

Edited post to make it clearer what I have a problem with. This is NOT about opening the File select dialog, this is about finding the correct dialog that goes with $oIE

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites
DaleHohm

See my sig for other solutions.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
corgano

The issue isn't making the dialogue appear, It does appear and the script continues running. And I could assume that any dialogue that appears is the one the script wants. I wanted to have some way to confirm a file select dialogue is associated with my $oIE, or a way to find the dialogue with $oIE as it's parent

I already use the solution in your sig "input type=file" link! Slightly modified, but it works

Func _IE_UploadFiles(ByRef $oIE, $aFiles, $sForm = "Form", $sButton = "Upload")
    local $oForm, $iFile, $File, $hIE = _IEPropertyGet($oIE, "hwnd"), $x, $y
    If Not IsArray ($aFiles) Then $aFiles = StringSplit($AFiles,"|")

    $oForm = _IEFormGetObjByName($oIE, $sForm)

    for $iFile = 1 to $aFiles[0]
        $File = $aFiles[$iFile]

        ConsoleWrite("Uploading "&$File&@CRLF)

        Do
            $oButton = _IEFormElementGetObjByName($oForm,$sButton)
            $oIE.document.parentwindow.scroll(0, 400)
            $x = _IEPropertyGet($oButton, "browserx") + _IEPropertyGet($oButton, "width") - 10
            $y = _IEPropertyGet($oButton, "browsery") + _IEPropertyGet($oButton, "height")/2 - 400
            $a = ControlGetPos($hIE , '', "[CLASS:Internet Explorer_Server; INSTANCE:1]")
;~          ConsoleWrite($x&", "&$y&@CRLF)
;~          MouseMove($x+$a[0], $y+$a[1]+26)
            ControlClick($hIE , '', "[CLASS:Internet Explorer_Server; INSTANCE:1]", "primary", 1, $x, $y)
;~          Exit
            sleep(400)
            $hChoose = _IE_GetFileSelectWindow($oIE)
        Until $hChoose <> 0



        WinSetTitle($hChoose,'',$hChoose)
;~      WinSetTitle($hIE,'',$hChoose)
        sleep(100)
        Do
            ControlSetText($hChoose, '', "Edit1", $File)
;~          ConsoleWrite(@error&"   "&ControlGetText($hChoose, '', "Edit1")&@CRLF)
            sleep(50)
        Until ControlGetText($hChoose, '', "Edit1") = $File

        Do
            sleep(100)
            ControlClick($hChoose, '', "Button2")
        Until not WinExists($hChoose)
        sleep(1000)

    Next

    return 1
EndFunc

I also added a bit that will scroll the page down. It's not perfect, I could calculate the EXACT amount needed to scroll down, but in my case it works perfectly. The dialogue opens every time

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Share this post


Link to post
Share on other sites
DaleHohm

Sorry, I understand your desire now, but have not had a need to dig into it further.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
corgano

Anyone else? This is driving me crazy. It's the last thing in my script, and I don't want to have to assume that the next dialog to pop up belongs to my window and not another. I hate assuming things in my scripts :(

The solution in this thread '?do=embed' frameborder='0' data-embedContent>>

also didn't help me. What's with IE10?

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

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  

  • Similar Content

    • TLAM
      By TLAM
      Hello,
      I am working on an autoIT script for CyberArk which is running Internet Explorer and connecting the user to a web application.
      For an unknown reason (I cannot explain why), IE has some trouble to start, only after a long disconnecting period (morning or after lunch). If he tries again, no problem, IE starts.
      I open a case with CyberArk but I am also searching a workaround, I thought to kill the process directly, or set a timeout with _IELoadWait but the process is not really created..

      May do you have any ideas for helping me ?

      Thanks in advance
       
    • Seminko
      By Seminko
      Wrote a script that grabs all of the IP addresses from Netflix's IP log, checks the IPs and returns suspicious activity.
      Everything works as it should but only when _IECreate is set to visible. When visible is set to false, it fails to login for some reason.
      Any ideas what might cause it and/or how to circumvent that?
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • hemichallenger
      By hemichallenger
      Hello,
      If anyone can help, it would be greatly appreciated. The code is just an example and similar to the issue with an internal webpage. I'm trying to autofill than click the submit button. I get the same error running the script.
      _IEFormElementSetValue, $_IESTATUS_InvalidObjectType
      IEGetObjById, $_IESTATUS_NoMatch
      Is it possible to edit the <textarea></textarea>  field with AutoIt?  If anyone could assist me on how. Than I could have a better understanding and chance in figuring it out on my main script. Thank you
      #include <IE.au3> Local $oIE1 = _IECreate ("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea") _IELoadWait($oIE1) local $oFormCollection = _IEFormGetCollection($oIE1,0) local $oid = _IEGetObjByid($oFormCollection, "iframeResult") _IEFormElementSetValue($oid, "test") sleep (2000) Local $oIE2 = _IECreate ("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_scripts_intro") _IELoadWait($oIE2) $oForm2 = _IEFormGetCollection($oIE2,0) $oClickMe = _IEGetObjById($oForm2, "demo") _IEAction($oClickMe, "focus") _IEAction($oClickMe, "click")
×