Forum Discussion

kevin_kapell's avatar
kevin_kapell
Frequent Contributor
9 years ago

URL is being entered into the wrong browser tab

I am trying to script opening a new tab in a web browser and navigating to a URL in the new tab.

However what happens is I get the new tab but the URL is being entered into the first tab 9the one that was open before I opened the new tab.

 

Here is the code.

 

function testcode(){
Log.Message("used for testing parts of code");

var browser, page, login, launch;

browser = Sys.Browser("*");
page = browser.Page("*");
browser.BrowserWindow(0).Keys("^t");
page.Wait();
// page.ToUrl(GlobalFunctionsHelpDesk.testsiteurl + '/shopadmin.asp');
page.ToUrl('yahoo.com');
}

  • Calling the Page("*") method with an asterisk is always going to return the first opened tab in the browser. You can usually name map different Pages, or pass in the URL and index when calling the Page() method.

     

    Here's the doc for the Page()

    • EVarnavsky's avatar
      EVarnavsky
      Icon for Alumni rankAlumni

      Please use ToUrl method of a Browser object. This method uses a first visible page - the new tab in this case,

       

      function testcode(){
      var browser, page;
      browser = Sys.Browser("*");
      browser.BrowserWindow(0).Keys("^t");
      page = browser.ToUrl('yahoo.com');
      }