Forum Discussion

lambada's avatar
lambada
Contributor
6 years ago
Solved

navigation browser / page

Hi everybody.

 

I would like to declare the page (browser) because I need it later to access on it on other objects. The necessary page is already open.

 

I used:

 

function DB() {

 

var url = "http://.............../";

Browsers.Item(btChrome).Run(url);

 

var page = Sys.Browser("*").Page(url);


Sys.Browser().BrowserWindow(0).Maximize();

 

...

}

 

When I use it, the page will a kind of "refresh" with this code. 

What can you alternatively recommend me how to do it?

 

Thank you very much in advance!

  • Even easier than that.

     

     

    function getMyPage(url){
       return Sys.Browser('chrome').Page(url);
    }

     

    That is, assuming that the desired page exists.

     

    In truth, though, I would map the object.  So, there would be, in my NameMapping, something like

     

    Aliases.browser.pageMyPage

     

    the pageMyPage object would have as the identifying properties the ObjectType of Page and then url being the the url.  Then, everytime I want to reference that page in my code, all I need to do is reference the Alias.

     

    And, one step further, if I want to make sure, when I'm referencing the page, that it actually exists and do validation on it (like if I click a button and expect a particular page), I can do something like

     

    Aliases.browser.myFirstPage.myNavigateButton.ClickButton();
    if (!Aliases.browser.WaitAliasChild('mySecondPage', -1).Exists){
        throw Error('The desired page did not come up after clicking on my button');
    }

     

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You're calling the "run" method on your browser object... by definition, that will attempt to run a copy of your browser to the URL in question.

     

    Instead of "Run", all you really need to do is assign your variable... there's no need to run the browser simply to get the page.

     

    Additionally...  if you're using NameMapping, there's no need for the code you've written.  A page can be mapped and then, everytime you need to access the page, you simply reference the Alias for it.

    • lambada's avatar
      lambada
      Contributor

      Thank you very much!

       

      So you mean, instead of "run" i have to take "page"? Like Browsers.Item(btChrome).page; ?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Even easier than that.

         

         

        function getMyPage(url){
           return Sys.Browser('chrome').Page(url);
        }

         

        That is, assuming that the desired page exists.

         

        In truth, though, I would map the object.  So, there would be, in my NameMapping, something like

         

        Aliases.browser.pageMyPage

         

        the pageMyPage object would have as the identifying properties the ObjectType of Page and then url being the the url.  Then, everytime I want to reference that page in my code, all I need to do is reference the Alias.

         

        And, one step further, if I want to make sure, when I'm referencing the page, that it actually exists and do validation on it (like if I click a button and expect a particular page), I can do something like

         

        Aliases.browser.myFirstPage.myNavigateButton.ClickButton();
        if (!Aliases.browser.WaitAliasChild('mySecondPage', -1).Exists){
            throw Error('The desired page did not come up after clicking on my button');
        }