Jump to content
Sign in to follow this  
ssah8

2 windows with same name

Recommended Posts

12 minutes ago, Juvigy said:

Try something like this:

Local $i = 1
While 1
    $oIE = _IEAttach("", "instance", $i)
    If @error = $_IEStatus_NoMatch Then
        $oIE = 0
        ExitLoop
    EndIf
    ConsoleWrite(_IEPropertyGet($oIE, "locationurl") &@CRLF)
    ConsoleWrite(_IEPropertyGet($oIE, "hwnd") &@CRLF)
    $i += 1
WEnd

 

What should "instance" be?

Share this post


Link to post
Share on other sites

Parameter. This code will attach to all open windows and output the handle and the url. You will see that the 2 windows with the same name have different handles.

Share this post


Link to post
Share on other sites
33 minutes ago, Juvigy said:

Parameter. This code will attach to all open windows and output the handle and the url. You will see that the 2 windows with the same name have different handles.

What if the url is different for every user? Based on the user who uses the bot, a different link will show up. It will show up a link with a /(username) in the end. 

Share this post


Link to post
Share on other sites

You wanted to attach when 2 windows with the same name - this is how you do it.  It doesnt matter the link - you attach to all with a loop. Then you identify your window and put an IF inside and return the correct object.

Share this post


Link to post
Share on other sites
#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

               Local $i = 1
               While 1
                  $oIE2 = _IEAttach("", "instance", $i)
                  If @error = $_IEStatus_NoMatch Then
                     $oIE = 0
                     ExitLoop
               EndIf
               ConsoleWrite(_IEPropertyGet($oIE, "locationurl") &@CRLF)
               ConsoleWrite(_IEPropertyGet($oIE, "hwnd") &@CRLF)
               $i += 1
               WEnd


               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

So as you can see at the end of the code, I inserted your code. But AutoIt gives me this error:

--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch
--> IE.au3 T3.0-2 Error from function _IETagNameGetCollection, $_IESTATUS_InvalidDataType
"C:\Users\Admin\Desktop\My Programs\YTMonster Bot\YTMonster bot.au3" (87) : ==> Variable must be of type "Object".:
For $oInput In $oInputs
For $oInput In $oInputs^ ERROR
>Exit code: 1    Time: 46.46

Share this post


Link to post
Share on other sites

Of course. It depends what exactly you want to do. It just illustrates how to attach to " 2 windows with the same "

Share this post


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

Of course. It depends what exactly you want to do. It just illustrates how to attach to " 2 windows with the same "

Sorry for posting 2 posts quickly after each other, please read my previous post.

Share this post


Link to post
Share on other sites

This is because my code attaches to the windows , display the urls and then set the object to 0. So you need to put an IF inside and when the attached window is the right one - to return the IE object and exit the loop. Post the URLs that my code produces and tell me to which one you want to attach

Share this post


Link to post
Share on other sites
5 minutes ago, Juvigy said:

This is because my code attaches to the windows , display the urls and then set the object to 0. So you need to put an IF inside and when the attached window is the right one - to return the IE object and exit the loop. Post the URLs that my code produces and tell me to which one you want to attach

Your code produces those two links:

https://www.ytmonster.net/download
0x00090B5C
https://www.ytmonster.net/download
0x00090B5C

(which are the same)

That link is the link before it clicks on the button. The button has this url https://www.ytmonster.net/client/

Edited by ssah8

Share this post


Link to post
Share on other sites
#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 $i = 1
               While 1
                  $oIE2 = _IEAttach("", "instance", $i)
                  If @error = $_IEStatus_NoMatch Then
                     $oIE = 0
                     ExitLoop
               EndIf
               ConsoleWrite(_IEPropertyGet($oIE2, "locationurl") &@CRLF)
               ConsoleWrite(_IEPropertyGet($oIE2, "hwnd") &@CRLF)
               $i += 1
               WEnd

               Local $oInputs = _IETagNameGetCollection($oIE, "button")
               For $oInput In $oInputs
                  If $oInput.classname == "button blue" Then _IEAction($oInput, "click")
               Next
            
               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

I changed the placement of your code. Because I want to interact with the first popup. At that popup, there is another button, that if clicked, it opens up a YouTube video to like. So, I need to paste your code after the popup aswell, to get the handle of the next popup. All this sounds so confusing xD

Output still the same, so, here is the output you asked for:

https://www.ytmonster.net/download
0x001E09E0
https://www.ytmonster.net/client/ssah8
0x000E0BC4
--> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch

The first one is before it clicks the first button. The second is the first popup (which I want to interact with).

Share this post


Link to post
Share on other sites

OK , so check with my code before you click the button and save the handles of the existing windows. After you click the button check again - you will have one more compared to the first list. That is the one you need. So if when you first check you have 2 windows with handles 1='xxxxx' , 2 = 'yyyyy' and then you have 3 windows windows with handles 1='xxxxx' , 2 = 'yyyyy' , 3 'zzzzzz' - compare the 2 arrays and attach to the unique element 'zzzzz'. I am not sure , but it may be easier to attach to the last element on the second check. I think the newest window is always last - test that to verify!

Share this post


Link to post
Share on other sites

That's easy;

Local $i = 1
While 1
    $oIE = _IEAttach("","instance", $i)
    If @error = $_IEStatus_NoMatch Then
        $oIE = 0
        ExitLoop
    EndIf
    ConsoleWrite(_IEPropertyGet($oIE, "locationurl") &@CRLF)
    $i += 1
WEnd
$oIE = _IEAttach("", "instance", $i-1)
ConsoleWrite(_IEPropertyGet($oIE, "locationurl") &@CRLF)

 

Share this post


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

  • Similar Content

    • By Lourens
      Hi,
      I am looking for a way to automate login to a Internet Banking website (https://bank.tymedigital.co.za/) and all of the examples that I could found still do not solve my issue with this website.
      In order to Login, the user need to enter their Identity Number and Password the click the Login button.
      Inspecting the Elements in Chrome are as follow;
      Identity Number
      <input autocomplete="username" placeholder="Please enter your South African ID number" maxlength="13" type="tel" class="form-control" value=""> Password
      <input autocomplete="current-password" placeholder="Enter password" type="password" class="form-control" value=""> Button
      <button type="button" class="btn btn-yellow btn-block">Login</button> Any assistance or directing me to a solution will be appreciated.
      Thank you,
      Lourens
    • By tommytx
      ConsoleWrite("Hello Dolly on Line 1" & @CRLF) #include <IE.au3> ConsoleWrite("Hello Dolly on Line 5" & @CRLF) Local $oIE = _IECreate("www.autoitscript.com") ConsoleWrite("Hello Dolly on Line 10" & @CRLF) Can anyone put me on the right track to troubleshoot this one.. the IE browser is not opening.. it is not my primary browser since FF is but that has not been a problem in the past.. it all seems to work including compile but the generation of the IE browser.. Never had any problem before.. below is the results of the run.. any ideas on where I might look.. that is the only error i get and its only after a 30 second delay.. I suppose a time out..
       
      ; >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "G:\show_pos.au3\test.au3"
      ; Hello Dolly on Line 1
      ; Hello Dolly on Line 5
      ; --> IE.au3 T3.0-2 Error from function _IECreate,  (Browser Object Creation Failed)
      ; Hello Dolly on Line 10
      ; >Exit code: 0    Time: 30.46
       
    • By ohaya
      Hi,
      I am still really new with AutoIT.  We are using it to automate logging into web sites and I have encountered problems with focus.  The target web page is configured to put the cursor into the first text field (username) when the page is loaded, and when I run the AutoIT script, which does the log in seems like it is just not starting where I expect it to be.  
      I have been kind of using ToolTip() to kind of help with debugging, but now I am wondering if the calls to ToolTip() are causing the focus to be messed up.  
      For example, at least visually, when the ToolTip() is called, I can see the cursor disappear from the web page text field and they when I do anything that is supposed to send keystrokes, they are going off somwhere else ("never-neverland").
      But when I remove some of the ToolTip() calls, it works correctly.
      So the questions I have are:
      1) Do the ToolTip() calls interfere with/change where the focus on the target page are?
      2) In general, what are the "rules" for where ToolTip can be used "safely" (== doesn't interfere with focus)?
      Thanks,
      Jim
       
    • By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
      Brian
    • By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
×
×
  • Create New...