Forum Discussion

AlexBorelli's avatar
AlexBorelli
Contributor
9 years ago

Error performing new attempt to see if a window is open

Good morning


I'm trying to check if a window is open. If you are not open I try again. But if the window is not open the TestComplete displays error in the log.

 

How do I solve this?

 

Follow the code below:

 

procedure grupo_clientes;
var vezes;
begin
   vezes := 0;
   for vezes := 0 to 3 do
      begin
         if Aliases.control.Grupo_Clientes.VisibleOnScreen <> True then
            begin
               Aliases.control.Principal.Keys('~c');
               Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
               Aliases.control.Principal.ToolBar1.PopupMenu.Click('[2]');
            end;
      end;
end;

 

 

Thank you.

 

Alex Borelli

  • AlexBorelli's avatar
    AlexBorelli
    9 years ago

    Hi

     

    It's OK. My code after your help.

     

    procedure clientes;
    var vezes;
    begin
       vezes := 1;
       for vezes := 1 to 3 do
        begin
          if not(Aliases.control.WaitAliasChild('Clientes', 500).Exists) then
            begin
              Aliases.control.Principal.Keys('~c');
              Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
              Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
              Log.Message('Essa é a ' + IntToStr(vezes) + 'ª tentativa de acesso ao menu.')               
            end        
          else
            if not Aliases.control.Clientes.Visible then
              begin
                Aliases.control.Principal.Keys('~c');
                Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
                Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
                Log.Message('Essa é a ' + IntToStr(vezes) + 'ª tentativa de acesso ao menu. Janela ja existia na memoria.')               
              end
          end
    end;

    Thank you.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    First of all, what is the error you're getting in the TestComplete log? Depending upon the error, the answer may vary.

     

    That said, VisibleOnScreen may not be the best property to check. VisibleOnScreen ASSUMES that the object exists but, for some reason, is not visible on the screen. If Grupo_Clientes actually does NOT exist and you want to make sure it exists, you should use the Exists property. However, that property also assumes the object is present first so you should, first of all, use WaitAliasChild.  So, I'd change your code to something like:

    procedure grupo_clientes;
    var vezes;
    begin
       vezes := 0;
       for vezes := 0 to 3 do
          begin
             if not(Aliases.control.WaitAliasChild('Grupo_Clientes', 10000)) then
                begin
                   Aliases.control.Principal.Keys('~c');
                   Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
                   Aliases.control.Principal.ToolBar1.PopupMenu.Click('[2]');
                end;
          end;
    end;
    • AlexBorelli's avatar
      AlexBorelli
      Contributor

      Thanks for the feedback.

       

      Test if this open window to call the routine again. Because sometimes the TestComplete can not click on the menu. And error occurs because of it.

      I auditioned with the code that you gave me, and the error occurred:

       

      Invalid variant operation ($ 80,020,003)
      Member not found
      Error location:
      Unit: "TestProject1 \ checklist \ Script \ menu_control"
      Line: 7 Column: 73.

       

      I take and I forward image with error rotating the original routine and the last pass.

       

      Thank you very much

       

      Alex Borelli

       

      WaitVisibleOnScreen

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Whoops! My bad... should have made the code read:

        procedure grupo_clientes;
        var vezes;
        begin
           vezes := 0;
           for vezes := 0 to 3 do
              begin
                 if not(Aliases.control.WaitAliasChild('Grupo_Clientes', 10000).Exists) then
                    begin
                       Aliases.control.Principal.Keys('~c');
                       Aliases.control.Principal.ToolBar1.PopupMenu.Click('[0]');
                       Aliases.control.Principal.ToolBar1.PopupMenu.Click('[2]');
                    end;
              end;
        end;

        Note that the "Invalid Variant Operation" error is because I was trying to treat an object as a boolean... adding the "Exists" property to the end corrects that.  Give this a try and see what happens.