Jump to content

Get file select window associated with $oIE


corgano
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
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
 Share

×
×
  • Create New...