Sign in to follow this  
Followers 0
ssah8

2 windows with same name

38 posts in this topic

Hello.

I am trying to attach a window, but the problem is that there is already another window with the exakt same title. How do I do that?

(_IEAttach)

Share this post


Link to post
Share on other sites



How do I get the window handle? And how would the _IEAttach look like?

Share this post


Link to post
Share on other sites

WinGetHandle is one way.  You'll need to find someway to distinguish between the windows if they have the same name by say checking contents of window (controls and data) Try searching for some examples.

According to the help file article for _IEAttach(), the second parameter allows you to select the "mode" of operation,  So, by providing the window handle as the first param and providing the string "hwnd", guess what should happen?

Share this post


Link to post
Share on other sites

Where do I see the handle in the window info tool?

Share this post


Link to post
Share on other sites

$oIE2 = _IEAttach(0x00000000001A0C30, "embedded", 0)

This gives me this message:

"C:\Users\Admin\Desktop\backup.au3" (74) : ==> Variable must be of type "Object".:
For $oInput In $oInputs
For $oInput In $oInputs^ ERROR

 

Share this post


Link to post
Share on other sites

Post a screenshot of the AutoIt Window Info tool when you hover over the window in question.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

There might be a problem in the code, that screws up everything. I can paste the whole program here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("YTMonster | Bot", 330, 245, 192, 124)
$Group1 = GUICtrlCreateGroup("Login", 0, 0, 137, 169)
$username = GUICtrlCreateInput("Username", 8, 48, 121, 21)
$password = GUICtrlCreateInput("Password", 8, 80, 121, 21)
$Login1 = GUICtrlCreateButton("Login", 8, 112, 123, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Start", 136, 0, 185, 169)
$Pic1 = GUICtrlCreatePic("C:\Users\Admin\Desktop\147863078766323.jpg", 144, 16, 172, 52)
$start = GUICtrlCreateButton("Start", 144, 80, 171, 81)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Points", 8, 176, 169, 65)
$points1 = GUICtrlCreateLabel("0", 16, 200, 15, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Made by DanCodes", 192, 200, 98, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
logintosite()

Func logintosite()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

         Case $Login1
            Global $oIE = _IECreate("https://www.ytmonster.net/login")

            $username1 = GUICtrlRead($username)
            $password1 = GUICtrlRead($password)

            $emailform = _IEGetObjByName($oIE, "usernames")
            $usernameform = _IEGetObjByName($oIE, "passwords")


            _IEFormElementSetValue($emailform, $username1)
            _IEFormElementSetValue($usernameform, $password1)


            Case $start

               Local $oInputs = _IETagNameGetCollection($oIE, "button")
               For $oInput In $oInputs
                  If $oInput.classname == "btn btn-success" Then _IEAction($oInput, "click")
               next

               sleep(10000)

               _IENavigate($oIE, "https://www.ytmonster.net/download")

               sleep(3000)

               Local $oInputs = _IETagNameGetCollection($oIE, "div")
               For $oInput In $oInputs
                  If $oInput.classname == "btn btn-large btn-primary" Then _IEAction($oInput, "click")
               Next

               sleep(3000)

               Local $oInputs = _IETagNameGetCollection($oIE, "button")
               For $oInput In $oInputs
                  If $oInput.classname == "button blue" Then _IEAction($oInput, "click")
               Next

               $oIE2 = _IEAttach(0x00000000001A0C30, "embedded", 0)

               Local $oInputs = _IETagNameGetCollection($oIE2, "div")
               For $oInput In $oInputs
                  If $oInput.classname == "btn btn-success btn-sm" Then _IEAction($oInput, "click")
               Next



               sleep(2000)




   EndSwitch
WEnd
EndFunc

Now, with the new GUI, this error pops out, which is really weird

Unknown function name.:
Global $oIE = _IECreate("https://www.ytmonster.net/login")
Global $oIE = ^ ERROR

Edited by ssah8
Changed the GUI

Share this post


Link to post
Share on other sites

Can anyone reply?

Share this post


Link to post
Share on other sites

ssah8,

Please do not bump your own threads within 24 hours.

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.  Be patient and someone will answer eventually.  Or if not - tough!

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
1 minute ago, Melba23 said:

ssah8,

Please do not bump your own threads within 24 hours.

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.  Be patient and someone will answer eventually.  Or if not - tough!

M23

 

Didn't think about that, sorry.

Share this post


Link to post
Share on other sites
2 hours ago, ssah8 said:

Unknown function name.:
Global $oIE = _IECreate("https://www.ytmonster.net/login")
Global $oIE = ^ ERROR

Looks like you forgot an include ...

Share this post


Link to post
Share on other sites
1 minute ago, mikell said:

Looks like you forgot an include ...

Haha, yeah, oh im stupid xD

Share this post


Link to post
Share on other sites

Now, the main question still remains unanswered.

Due there have been many questions, I will clarify what my main is:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("YTMonster | Bot", 330, 245, 192, 124)
$Group1 = GUICtrlCreateGroup("Login", 0, 0, 137, 169)
$username = GUICtrlCreateInput("Username", 8, 48, 121, 21)
$password = GUICtrlCreateInput("Password", 8, 80, 121, 21)
$Login1 = GUICtrlCreateButton("Login", 8, 112, 123, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Start", 136, 0, 185, 169)
$Pic1 = GUICtrlCreatePic("C:\Users\Admin\Desktop\147863078766323.jpg", 144, 16, 172, 52)
$start = GUICtrlCreateButton("Start", 144, 80, 171, 81)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Points", 8, 176, 169, 65)
$points1 = GUICtrlCreateLabel("0", 16, 200, 15, 29)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("Made by DanCodes", 192, 200, 98, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
logintosite()

Func logintosite()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

         Case $Login1
            Global $oIE = _IECreate("https://www.ytmonster.net/login")

            $username1 = GUICtrlRead($username)
            $password1 = GUICtrlRead($password)

            $emailform = _IEGetObjByName($oIE, "usernames")
            $usernameform = _IEGetObjByName($oIE, "passwords")


            _IEFormElementSetValue($emailform, $username1)
            _IEFormElementSetValue($usernameform, $password1)


            Case $start

               Local $oInputs = _IETagNameGetCollection($oIE, "button")
               For $oInput In $oInputs
                  If $oInput.classname == "btn btn-success" Then _IEAction($oInput, "click")
               next

               sleep(10000)

               _IENavigate($oIE, "https://www.ytmonster.net/download")

               sleep(3000)

               Local $oInputs = _IETagNameGetCollection($oIE, "div")
               For $oInput In $oInputs
                  If $oInput.classname == "btn btn-large btn-primary" Then _IEAction($oInput, "click")
               Next

               sleep(3000)

               Local $oInputs = _IETagNameGetCollection($oIE, "button")
               For $oInput In $oInputs
                  If $oInput.classname == "button blue" Then _IEAction($oInput, "click")
               Next

               $handle = 0x00000000001A0C30

               $oIE2 = _IEAttach(0x00000000001A0C30, "embedded", 0)

               Local $oInputs = _IETagNameGetCollection($oIE2, "div")
               For $oInput In $oInputs
                  If $oInput.classname == "btn btn-success btn-sm" Then _IEAction($oInput, "click")
               Next

               sleep(2000)


   EndSwitch
WEnd
EndFunc

That is the code, the whole code, the whole program (far away from finished). In order for me to move on, I have to get past the _IEAttach problem. 

This is what I currently have: $oIE2 = _IEAttach(0x00000000001A0C30, "embedded", 0)

This is of course not the right way, that's why AutoIT crashes on me. Now, can anyone please tell me what's wrong with the _IEAttach line? It's probably something very simple.

Share this post


Link to post
Share on other sites

The handle you are providing to the _IEAttach function is dynamic (it should change each execution at runtime).  You'll need a method to get the handle of the new window each time.

5 hours ago, spudw2k said:

WinGetHandle is one way.

If there isn't an easy way to distinguish between the "parent" and new IE windows within the confines of the function above you may have to get fancy and do some running process analysis.

Share this post


Link to post
Share on other sites

So could you provde we with an example on how to get the handle of a specific browser window?

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0

  • Similar Content

    • 5ervant
      By 5ervant
      Go create a quick account in Zapier and go to https://zapier.com/app/dashboard and make some Zaps!
      Just need to click the specific instance of an .open-menu button and then click its a.run (anchor) element.
      Doing this IE.au3 script just causing to click its container element:
      $target = 1; Target the first instance #include <IE.au3> $oIE = _IEAttach("Dashboard - Zapier") $count = 0; $tags = _IETagNameGetCollection($oIE, "div") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "open-menu" Then $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) ; $tag.fireEvent("onmousedown") ; _IEAction($tag, "click") ; $tag.fireEvent("onmouseup") ; Or this but not working ; $tag.Click EndIf EndIf Next I also tried to do it using FF.au3
      $target = 1; Target the first instance #Include <Array.au3> #Include <FF.au3> $count = 0; If _FFConnect(Default, Default, 3000) Then $aArray = _FFXPath( "//div[@class='open-menu']", "", 7 ) ; _ArrayDisplay($aArray) For $tag in $aArray $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) _FFClick($tag) EndIf Next EndIf Error: _FFClick ==> No match: $sElement: [number]
      Could some help me how to click such buttons on such kind of a dynamic page?
    • Phoenixx177
      By Phoenixx177
      I have a script that is calling 2 browser windows in my GUI and loading up the appropriate URLs.  Tested alone it works fine.  I also have another script that launches a 3rd party application in the GUI.  When I try to modify my 2nd script so that it includes the two browser windows along with the GUI, the GUI loads but not the browser windows.  Can someone get a second set of eyes on the script below and tell me where my brain jumped track please?  Many Thanks.
      #include <GUIConstants.au3> #include <Constants.au3> #include <windowsconstants.au3> #include <IE.au3> Global $oIE_google = _IECreateEmbedded() Global $oIE_autoit = _IECreateEmbedded() Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainWindow = GUICreate("Embed Cmd", 1280, 780, 10, 10) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState (@SW_SHOW) GUIRegisterMsg(0xF, "WM_PAINT") ; create a borderless window that is a child to the main window $embedWindow = GUICREATE("", 700, 400, 15, 15, $WS_POPUP, -1, $mainWindow) Global $google = GUICtrlCreateObj($oIE_google, 10, 10, 1000, 300) Global $autoit = GUICtrlCreateObj($oIE_autoit, 800, 10, 500, 300) _IENavigate($oIE_google, "http://www.google.com") _IENavigate($oIE_autoit, "http://www.bing.com") DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $embedWindow, "hwnd", $mainWindow) ; launch the command prompt (black on white, without the operating system message) $pid = run("C:\Program Files (x86)\Cisco\Router Manager\Router Administration.exe") ProcessWait ($pid) ; get the handle of the cmd window as i cannot be certain that there will be only one instance of the cmd running with the same window title or class $cmdHandle = _ProcessGetHWnd($pid, 2) $hWndChild = $cmdHandle[1][1] ; make the command prompt window a child to the earlier created borderless child window DllCall("user32.dll", "hwnd", "SetParent", "hwnd", $hWndChild, "hwnd", $embedWindow) ; resize the command prompt window so that its bolder and title bar are outside the borderless child window ; giving the appearance of a borderless command prompt WinMove($hWndChild, '', 10, 500, 485, 206) ;WinMove($hWndChild, '', 10, 500) WinSetState($hWndChild, '', @SW_SHOW) WinSetState($embedWindow, '', @SW_SHOW) WinSetState($oIE_google, '', @SW_SHOW) WinSetState($oIE_autoit, '', @SW_SHOW) ; inifinite event loop While 1 ; sleep for 100 milliseconds (to not hog the cpu) sleep(100) ; end of event loop WEnd Func CLOSEClicked() ; take care of things to do when exiting Winkill($hWndChild) Exit EndFunc Func WM_PAINT($hWnd, $Msg, $wParam, $lParam) Sleep(100) DllCall("user32.dll", "int", "InvalidateRect", "hwnd", $hWnd, "ptr", 0, "int", 0) EndFunc ;==>WM_PAINT ;=============================================================================== ; ; Function Name: _ProcessGetHWnd ; Description: Returns the HWND(s) owned by the specified process (PID only !). ; ; Parameter(s): $iPid - the owner-PID. ; $iOption - Optional : return/search methods : ; 0 - returns the HWND for the first non-titleless window. ; 1 - returns the HWND for the first found window (default). ; 2 - returns all HWNDs for all matches. ; ; $sTitle - Optional : the title to match (see notes). ; $iTimeout - Optional : timeout in msec (see notes) ; ; Return Value(s): On Success - returns the HWND (see below for method 2). ; $array[0][0] - number of HWNDs ; $array[x][0] - title ; $array[x][1] - HWND ; ; On Failure - returns 0 and sets @error to 1. ; ; Note(s): When a title is specified it will then only return the HWND to the titles ; matching that specific string. If no title is specified it will return as ; described by the option used. ; ; When using a timeout it's possible to use WinWaitDelay (Opt) to specify how ; often it should wait before attempting another time to get the HWND. ; ; ; Author(s): Helge ; ;=============================================================================== Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000) Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit() While 1 ; Get list of windows $aWin = WinList($sTitle) ; Searches thru all windows For $i = 1 To $aWin[0][0] ; Found a window owned by the given PID If $iPid = WinGetProcess($aWin[$i][1]) Then ; Option 0 or 1 used If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then Return $aWin[$i][1] ; Option 2 is used ElseIf $iOption = 2 Then ReDim $aReturn[UBound($aReturn) + 1][2] $aReturn[0][0] += 1 $aReturn[$aReturn[0][0]][0] = $aWin[$i][0] $aReturn[$aReturn[0][0]][1] = $aWin[$i][1] EndIf EndIf Next ; If option 2 is used and there was matches then the list is returned If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn ; If timed out then give up If TimerDiff($hTimer) > $iTimeout Then ExitLoop ; Waits before new attempt Sleep(Opt("WinWaitDelay")) WEnd ; No matches SetError(1) Return 0 EndFunc ;==>_ProcessGetHWnd $StaticTxt = ControlGetText("Embed Cmd","",1007) MsgBox(1,"Static Text", $StaticTxt) GUISetState() While GUIGetMsg() <> -3 WEnd  
    • Phoenixx177
      By Phoenixx177
      I've tried to wrap my head around it but just can't imagine how to embed 2 IE browsers in the same GUI.
      Here's what I'm doing so far.
       
      #include <GuiConstantsEx.au3> #include <windowsconstants.au3> #include <IE.au3> Global $oIE = _IECreateEmbedded() ; Create a simple GUI for our output Global $hGUI = GUICreate("Embedded Web control Test", 1280, 580, (@DesktopWidth - 1280) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN, $WS_MAXIMIZEBOX)) Global $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 1100, 500) _IENavigate($oIE, "http://xxxxxxxxxx.com") Global $o_doc = _IEDocGetObj($oIE) $o_doc.DocumentElement.ScrollTop = 140 $o_doc.DocumentElement.ScrollLeft = 170 GUISetState() While GUIGetMsg() <> -3 WEnd  
    • xuzo
      By xuzo
      Let's say I want to automate something, let's keep it very simple.
      On google site.
      - Move mouse to search box
      - Type in "cat"
      - Press "enter" to search
      Now I can do that no problem with mouse moves and so on, but is there a way to do it by code?
      So the user doesn't see the actions?
       
    • rusdady
      By rusdady
      Hi.
      Is there a way in autoit script to wait while browser's html document fully loaded, instead of putting script in Sleep?
      I have this code:
              
      Sleep(8000) $oDocument=_UIA_getFirstObjectOfElement($oIE,$cDocumentWindow, $treescope_subtree) Sleep(8000) If not isobj($oDocument) Then _UIA_DumpThemAll($oIE,$treescope_subtree) Else ...... EndIf  
      I do not like this - Sleep(8000). Sometimes it takes 2 seconds to load, sometimes it takes over 8 seconds...
      I would like to have something that would wait when html document is ready/loaded.
      Thank you.