Forum Discussion

shaifali_pandya's avatar
shaifali_pandya
Occasional Contributor
12 years ago

How to activate a specific page

In our test we are trying to not disturb any browser window which is not related to the tested WebSite but if there are multiple instances open of the tested website then close all but one.

Question is after comparing the page URL with the tested website's URL, how to activate the page?

7 Replies


  • Hi Shef,


     


    You can click the needed tab like this:




    //JScript


    Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand.TabButton("<URL>").Click();



  • shaifali_pandya's avatar
    shaifali_pandya
    Occasional Contributor
    Thanks Tanya.

    Unfortunately, it does not work as the object Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand.TabButton("<Url>")does not exists.

    I would like to understand why your suggestion did not work.



    Following is working with the current test -



    if MyPage.contentDocument.title = empty then

       Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand.TabButton(MyPage.contentDocument.domain).Click

    else

       Sys.Browser("iexplore").BrowserWindow(0).CommandBar.TabBand.TabButton(MyPage.contentDocument.title).Click

    end if
  • shaifali_pandya's avatar
    shaifali_pandya
    Occasional Contributor
    Had assumed that URL had to be replaced with actual URL.

    Do you think without replacing URL, it would work?
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 2 rankChampion Level 2
    Hi Shef,



    Assuming that you already have the reference to the page and using the code Tanya posted some time ago in another thread (untested VBScript pseudocode):




    '-----------------------------------------------------------------------------



    ' Returns BrowserWindow object that corresponds to the given page object

    ' From: http://smartbear.com/forums/f75/t83264/how-to-match-a-page-object-to-its-browserwindow

    Function BrowserWindowByPageGet(ByRef page)

      Const cProcName = "BrowserWindowByPageGet"

      Dim cProcNameMsgPrefix : cProcNameMsgPrefix = cUnitNameMsgPrefix & cProcName & "(): "



      Dim title

      Dim wnd



      Set wnd = Utils.CreateStubObject

      If (Not IsNull(page)) Then

        If (0 = aqString.Compare(page.ObjectType, "Page", False)) Then

          title = page.contentDocument.title

          Set wnd = page.Parent.FindChild("WndCaption", title & "*")

          If (Not wnd.Exists) Then

            Set wnd = page.Parent.FindChild("WndCaption", Project.Variables.pvtBaseURL)

          End If

        End If

      End If

      Set BrowserWindowByPageGet = wnd

    End Function

    '-----------------------------------------------------------------------------



      Call BrowserWindowByPageGet(page).Activate



    Is this what you were looking for?



  • Try this, worked for me:



    function switchToPage(page){


      Sys.Browser("chrome").Page(page).Click();


    }


  • Here an option for who working with windows and not tabs:



    function switchToPage(expectedPage){


      


      expectedPage += " - Google Chrome";


      


      var pages = Sys.Process("chrome").FindAll("ObjectType","BrowserWindow").toArray();


     


      for(var i = 0; i < pages.length; i++){


        if (pages.Caption == expectedPage){


          pages.Activate();


          return;


        }


      }


      


      Log.Error("Page not founded");


     


    }