Forum Discussion

ḥari's avatar
ḥari
Frequent Contributor
2 years ago

Page variable for new tab in mobile testing

Hi
In mobile testing while opening a new tab and the page variable want to point out that new tab.
Refer the below code which I am using for page variable

Virtual Browser. Item(devices[k]). Run(s) ;
Let browser=Aliases.browser;
Let page=browser.page("*") ;

How to navigate the page variable to newtab

10 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Am I getting you right: there is a page in the browser and the variable that references this page. The page contains a link and new page in new tab is opened when this link is clicked. You like your variable to start referencing this new page when it is opened. Is my understanding correct?

    If it is, then you need to make definitions for browser and page to be unique enough to let TestComplete to understand what you need.

    Your current definition for the variable (Let page=browser.page("*"); ), translated to plain human, says: look for any page opened in the browser and return a reference to it.

    Any reason for TestComplete to change the referenced page when it is provided with the above definition?

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If you want to get a reference to the new tab page, then try this code

     

    function SwitchBetweenTabs()
    {
        // Open page
        VirtualBrowsers.Item("Apple iPad").Run("https://www.w3schools.com/html/default.asp");
        
        // New tabs
        NameMapping.Sys.browser.Page("https://www.w3schools.com/html/default.asp").Keys("^t");
    
        // Reference to new tab page
        NameMapping.Sys.browser.Page("chrome://newtab/");
        var page = NameMapping.Sys.browser.Page("chrome://newtab/");
        Log.Message(page.URL);
    }

     

    Which is similar to my previous code, with the exception of the last two lines added

    • ḥari's avatar
      ḥari
      Frequent Contributor
      I need to fetch that new tab page URL in log file. So, in web testing

      Var newPage=Sys.Browser(browser[k]). Page("*") ;
      Log. Message (newPage.URL) ;

      Like this I want in virtual browser. I tried but I doesn't works. Help me out
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I thought you wanted help in "How to navigate the page variable to new tab"?

     

    The code will work for virtual browser,

    VirtualBrowsers.Item("Apple iPad").Run("https://www.w3schools.com/html/default.asp");
    Log.Message(NameMapping.Sys.browser.Page("*").URL);

     

     

     

    • ḥari's avatar
      ḥari
      Frequent Contributor
      Yeah,you are correct only I want to navigate to page variable to new tab only.
      That new page URL only want to fetch and need to hit click button on the new tab page.
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You can't navigate or switch tabs based on your "page variable". 

    • ḥari's avatar
      ḥari
      Frequent Contributor
      But we are doing in web testing know through this code
      Var newPage=Sys.Browser(browser[k]). Page("*") ;
      Why we can't do it in this
      May I know the reason
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Ignore my previous statement, I just figured out it can be done,

     

    function SwitchBetweenTabs()
    {
        // Open page
        VirtualBrowsers.Item("Apple iPad").Run("https://www.w3schools.com/html/default.asp");
        
        // New tabs
        NameMapping.Sys.browser.Page("https://www.w3schools.com/html/default.asp").Keys("^t");
        NameMapping.Sys.browser.Page("chrome://newtab/").ToUrl("https://www.w3schools.com/css/default.asp")
        NameMapping.Sys.browser.Page("https://www.w3schools.com/css/default.asp").Keys("^t");
        NameMapping.Sys.browser.Page("chrome://newtab/").ToUrl("https://www.w3schools.com/js/default.asp")
        
        // Switch between tabs
        NameMapping.Sys.browser.Page("https://www.w3schools.com/html/default.asp").Click();
        NameMapping.Sys.browser.Page("https://www.w3schools.com/css/default.asp").Click();
        NameMapping.Sys.browser.Page("https://www.w3schools.com/js/default.asp").Click();
    }

     

    You can use the above code to achieve what you need to do.

    • ḥari's avatar
      ḥari
      Frequent Contributor
      Did you understand my question
      In 1st tab i have an link while I am clicked it will be opened as a newtab so my page variable control is not in the newtab.