Forum Discussion

kevin_kapell's avatar
kevin_kapell
Frequent Contributor
7 years ago

Cannot tell when a web page is not present

Using Firefox there is a new page that is sometimes displayed during my testing. When it is present there are no problems. When it is not I need to click a link to display the page.

The problem is that I get an error when the page is not there even though I am using the .Exists check in an if statement.

 

Reference the code that follows:

When the page https://somepage.com/* is present this has no problem. It falls right past the if statement correctly. However when the page is not present I get the error "The page 'https://somepage.com/*' was not found." instead of it going into the if statement and doing the click action.

 

CODE:

function AddSomething() {

  var browser = Sys.Browser("*");
 
  if( browser["Page"]("https://somepage.com/*")["Exists"] == false)
  {
    Aliases["MyLink"]["Click"]();
  }

  var Mypage = browser.Page("https://someplace.com/*");
 
  Mypage .Wait();

  do stuff ....

}

  • tristaanogre's avatar
    tristaanogre
    7 years ago

    My bad.. I'm not used to C#Script syntax...

    Should be as follows:

    function AddSomething() {
    
      var browser = Sys.Browser("*");
     
      if( browser["WaitPage"]("https://somepage.com/*",  0, 20000)["Exists"] == false)
      {
        Aliases["MyLink"]["Click"]();
      }
    
      var Mypage = browser.Page("https://someplace.com/*");
     
      Mypage .Wait();
    
      do stuff ....
    
    }
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You need to update your code to use WaitPage.  Think of it like this... how do you check the "Exists" property of an object that doesn't exist?  WaitPage returns either the page being waited for OR a stub object with the Exists property set to "false".

     

    function AddSomething() {
    
      var browser = Sys.Browser("*");
     
      if( browser["Page"]["WaitPage"]("https://somepage.com/*", 20000)["Exists"] == false)
      {
        Aliases["MyLink"]["Click"]();
      }
    
      var Mypage = browser.Page("https://someplace.com/*");
     
      Mypage .Wait();
    
      do stuff ....
    
    }
    • kevin_kapell's avatar
      kevin_kapell
      Frequent Contributor

      This results in the error "Object doesn't support this property or method" for the line 

      if( browser["Page"]["WaitPage"]("https://somepage.com/*", 20000)["Exists"] == false)

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        My bad.. I'm not used to C#Script syntax...

        Should be as follows:

        function AddSomething() {
        
          var browser = Sys.Browser("*");
         
          if( browser["WaitPage"]("https://somepage.com/*",  0, 20000)["Exists"] == false)
          {
            Aliases["MyLink"]["Click"]();
          }
        
          var Mypage = browser.Page("https://someplace.com/*");
         
          Mypage .Wait();
        
          do stuff ....
        
        }