Forum Discussion

akalogeropoulos's avatar
akalogeropoulos
Occasional Contributor
10 years ago

Access address bar Google Chrome

I need to able to read the URL in the addresse bar of Google Chrome. I'm not able to access the address bar with "Object Spy". Any suggestion?



Best regards,

Anastasios

1 Reply

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    The URL will be contained within the page object Name and FullName properties.



    Ex:



    Sys.Browser("chrome").Page("http://smartbear.com/forums/f75/t91569/access-address-bar-google-chrome/")



    Assuming you have only one page open you can retrieve the "address" like so:






    //JScript


    wshell = new ActiveXObject('WScript.Shell');


    myCurrentURL = Sys.Browser("chrome").Page('*').Name.replace(/page\(/i,'').replace('\"','');


    wshell.popup(myCurrentURL);





    If you want an array returned of all pages I wrote this function for you:






    //JScript


    wshell = new ActiveXObject('WScript.Shell');


    var myURLArray = listAllURL('chrome');


    for (var c = 0;c < myURLArray.length;c++){


     wshell.popup(myURLArray);


     }




    function listAllURL(myBrowser){


    var urlList = [];


    if (!Sys.WaitBrowser(myBrowser,0).Exists){


     return urlList;


     }


    var browserArray = VBArray(Sys.FindAll('Name','*' + myBrowser + '*',1,true)).toArray();


    for (var browser = 0;browser < browserArray.length;browser++){


     var objectArray = VBArray(browserArray[browser].FindAll(['Name'],['*Page*'],1,true)).toArray();


     for (var object = 0;object < objectArray.length;object++){


      var pageName = objectArray[object].Name.replace(/page\(/i,'');


      urlList.push(pageName.substr(1,pageName.length - 3));


      }


     }


    return urlList;


    }