Forum Discussion

sean_ng's avatar
sean_ng
Occasional Contributor
7 years ago

catch error then perform specific task

Hi,

 

during playback i get this error :

There was an attempt to perform an action at point (X, Y) which is transparent or out of the window bounds.

 

i know what is causing this error :

because my web page have scroll bar and test complete is trying to click on object with is hidden, if i manually drag the scroll bar to show the object, then the error is gone.

 

what i want to do :

i would like to catch this error by using an if,else script. If this error happen then i run a script to move the scroll bar

 

what i did :

i tried using 'try .. catch ..' but it does not work.

 

try
{
   obj.click();
}
catch (e)
{
  Log.Error(e.description + "Specific Text");
  //execute script here
}

how can i catch the error and then perform a specific script to move the scroll bar ?

  • This is because the type of error raised is not a code exception but an operation exception with the "click" action.  These are not caught by try/catch.

     

    Suggestion.  In your code for doing the object click, before the click, do a check for VisibleOnScreen. If VisibleOnScreen is false, then call obj.scrollIntoView(true).  This will scroll the web page to the component before the click.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    This is because the type of error raised is not a code exception but an operation exception with the "click" action.  These are not caught by try/catch.

     

    Suggestion.  In your code for doing the object click, before the click, do a check for VisibleOnScreen. If VisibleOnScreen is false, then call obj.scrollIntoView(true).  This will scroll the web page to the component before the click.

    • sean_ng's avatar
      sean_ng
      Occasional Contributor

      hi tristaanogre,

       

      Thank you for your reply.

      your suggestion work well for me

      below is the code i use, which is actually from AlexKaras

       

      if (!obj.VisibleOnScreen) {
      
          obj.scrollIntoView(true);
      
          if (!obj.VisibleOnScreen) {
      
              obj.scrollIntoView(false);
          }
      }
      
      obj.Click();
      • djt's avatar
        djt
        Occasional Contributor

        I have the same issue but in a Windows app rather thana web page

         

        Aliases.MyApp.HwndSource_MainWindow.MainWindow.m_NodeControl.ExpandItem(("|[2]"));
        Aliases.MyApp.HwndSource_MainWindow.MainWindow.m_NodeControl.Refresh();
        Aliases.MyApp.HwndSource_MainWindow.MainWindow.m_NodeControl.DblClickItem("|[2]|[0]");

         

        The third line craters if the tree view is scroll off the screen so node 2 is not visible

         

        I can't call is visible on the NodeControl as it always is

         

        How do I ensure node 2 is visible ?