Forum Discussion

aduddella's avatar
aduddella
Contributor
15 years ago

Getting the active page instance from VB Script

Hi



I am writing a script to get the page and browser object of the active IE window



Situation example



I have 2 tabs open in the IE Browser or two IE browsers opened and want to know the following



1.which is the latest one

2.Whcih browser window is currently active



Could anyone kindly guide me through this



Regards

Anand

7 Replies


  • Hi Anand,





    In case of opening several windows, the Internet Explorer process that corresponds to the latest window has the largest index. You can use the WaitProcess method to get the latest instance. Note that the script below assumes that there is at least one Internet Explorer window open:







    index = 1

    Do Until index=0

      index = index + 1

      If Not Sys.WaitProcess("iexplore", 0, index).Exists Then

        Exit Do

      End If

    Loop

    Log.Message("The latest launched window has the " & Sys.Process("iexplore", index - 1).Page("*").URL & " URL")







    To get the active window, use the Sys.Desktop.ActiveWindow method.





    As for the tabs, we do not recommend that you use tabbed browsing in your tests.





    Please clarify your task so we can try to suggest you another possible approach.


  • Dear Allen



    Thank you for the code but the code works when the pop up pages open as a different process under the Sys such as



    window 1 is under Sys - > Proceess ( "iexplore",2) then the pop up page open as a sys -> process ("iexplore",3)



    but in my case Test complete shows the pop up pages as a child of process("iexplore",2) only



    I am using IE8 as a browser .In this case what should be the code



    Regards

    Anand

  • Hi Anand,





    We need some detailing: as far as I understand, you need to learn what Internet Explorer pop-up window was the latest to open and what is active. What do you need that for? Please explain your task so we can try to suggest you a possible approach.


  • Dear Allen



    I am start my automated test from a single web page and perform some actions which will open a pop up windows which are like a wizard to complete certain tasks and then come back to the home page so when i come back there would be more than 1 browser which would be open so how would i go back or switch between browser or pages



    Regards

    Anand

  • Hi Anand,





    You can use the IEFrame method to address child windows of the Internet Explorer process. The first opened window has the 0 index, the second - 1, etc. To switch back to the previous window, call the Activate method of the previous frame:







    Call Sys.Process ("iexplore").IEFrame(0).Activate







    To close the opened window, call the Close method of the frame that corresponds to the opened window:







    Call Sys.Process("iexplore").IEFrame(1).Close




  • Hi Allen



    In my Test complete all the new windows i open open under Process("iexplore",2) as child windows



    I have the IE 8.0.60001 version of browser



    is there any change I have to do in the Test Complete testings



    Regards

    Anand
  • Hi Anand,



    Just address the process instance with the needed index:





    Call Sys.Process("iexplore", 2).IEFrame(0).Activate







    Call Sys.Process("iexplore", 2).IEFrame(1).Close