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

    • SkysLastChance
      By SkysLastChance
      I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 
      $tags = $oIE.document.GetElementsByTagName("input") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "fTs-p3298-l0 wplEditControl" Then $target = $tag ExitLoop EndIF Next MsgBox(0,"",$target) If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked") I have tried 
       MsgBox(0,"",$target.Attribute)  MsgBox(0,"",$target.Value)  MsgBox(0,"",$target.InnerText) I would expect to see this in the msgbox
      fTs-p3298-l0 wplEditControl  
    • SkysLastChance
      By SkysLastChance
      I am trying to grab the id "in2xk_26" however it the characters before the underscore always change. (in the name too)
      Is there a way I can find a id or name by the last 3 charcters?
      Using something like "stringright?"
      So I would want to search for just "_26" in this case.
      This is assuming that there are no other _26
       

      #include <Excel.au3> #include <IE.au3> #include <GUIConstantsEx.au3> Global $iMousespeed = 25,$target = "",$TagName = "",$Value = "",$Atrribute = "" $oIE = _IEAttach("MEDITECH") $TagName = "input" $Value = "in2xk_26" $Attribute = "id" $tags = $oIE.document.GetElementsByTagName($TagName) ;TagName ------ MAKE SURE TO NAME THESE For $tag in $tags $class_value = $tag.GetAttribute($Attribute) ;Attribute ------ MAKE SURE TO NAME THESE If string($class_value) = $Value Then ;Value ------ MAKE SURE TO NAME THESE $target = $tag $iScreenX = _IEPropertyGet($target, "screenx") $iScreenY = _IEPropertyGet($target, "screeny") $iWidth = _IEPropertyGet($target, "width") $iHeight = _IEPropertyGet($target, "height") $oMouseCords = MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed) MouseClick($MOUSE_CLICK_LEFT) ExitLoop EndIf Next  
       
    • SkysLastChance
      By SkysLastChance
      I was wondering how I read data inside of a iframe. I would like to be able to click something inside a iframe. However, I can't even find the tag. 
      The id and name change all the time so I can't use those. 
      The code highlighted in blue is what I am trying to click. (second picture)
      Here is what I have tried.
      $target = "" $tags = $oIE.document.GetElementsByTagName("div") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "s_92 altstyle s_93 s_94" Then $target = $tag ConsoleWrite("Tag Found " & $target.outerText&@CRLF) ExitLoop EndIf Next  

       
       

    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

    • SkysLastChance
      By SkysLastChance
      I am trying to type a name in patient summary search box. How should I go about doing this. I am clearly not doing it right. (Attached Picture of HTML code.)
      This is what I have tried. I assume this is not working because it is not a form? 
      WinActivate("MEDITECH - Internet Explorer")       Sleep (500)    $oIE = _IEAttach("MEDITECH")    $oForm = _IEFormGetObjByName($oIE, "systemMenu")    $oText = _IEFormElementGetObjByName($oForm, "sysmenu-searchbarinput") _IEFormElementSetValue($oText, "Hey! This works!")
×