Forum Discussion

hina's avatar
hina
Contributor
2 months ago

There was an attempt to perform an action on a zero-sized window

Hi,

I am working with Desktop application and I am trying to click on an object. I can click on the same object multiple times until I start receiving the error message: "There was an attempt to perform an action on a zero-sized window". I have tried few things to resolve this issue but nothing works:

  1. I have tried calling the Refresh method before clicking the object
  2. I have tried putting a delay before clicking the object
  3. I have checked the height and width of the object, it is not zero and is visible on screen

The only thing that work is when restart the application and try to click the same object, it doesn't give me that error until I click the same object multiple times I start receiving the same error message again.

What can I do to stop receiving this error?

Thanks,

Hina

32 Replies

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    Hello hina,

    I thought you were right to try a delay.  I did a quick community search and found 2 related solved issues.  Could you post a code snip?  Are you scripting or Keyword testing?

    Help with "Zero-sized Window" error? | SmartBear Community
    There was an attempt to perform an action on zero sized window | SmartBear Community

    Another idea is to verify the object state or insert a waitproperty method call.

    WaitProperty Method:
    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/waitproperty-method.html

    ... If you find my posts helpful drop me a like! ๐Ÿ‘ Be sure to mark or post the solution to help others out and/or to credit the one who helped you. ๐Ÿ˜Ž

    • hina's avatar
      hina
      Contributor

      Hi scot1967,

      Thank you for your reply. Here is my code:

      function test()
      {
        var WA = Sys["Process"]("AXISEL")["WinFormsObject"]("MainForm")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("NavigationBar")["WinFormsObject"]("WorkAreaView")["WinFormsObject"]("TV")["OutlineItem"]("TestComplete Work Area 1*");
        WA["Refresh"]();
        Delay(1000);
        
        WA["WaitProperty"]("VisibleOnScreen","True",2000);
        
        WA["Click"]();
      }

      I tried the WaitProperty method, it works sometimes and sometimes it doesn't.

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    P.S.  I would check Focusable, IsFocused, IsEnabled, Visible, VisibleOnScreen, IsVisible, Visibility.  One of these is likely being toggled between click actions.  

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    Hello again,  

    Since this is happening only on repeated click attempts I would log the related states of the WA object just prior to clicking the object to see if there are any differences between working and not.  It may give you another useful error if it is unable to log the state of the object.

     I would check Focusable, IsFocused, IsEnabled, Visible, VisibleOnScreen, IsVisible, Visibility.  One of these is likely being toggled between click actions.  

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    ... Some of these states may not apply to your object and there may be others you can check I have not listed here.  The delays seem to be needed in the solved cases to allow time for object state changes or creation.  

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    A screen shot of the object tree section you are working with may be helpful.  Expand it out to the child object you are trying to work with and include any relevant details of the objects.

    I once had to deal with an object that was a TextBlock until it was clicked on.  Then it became a TextBox I could add data in.  The manual GUI tests were fine but TC had to be coded to click the 'Block' and wait for the 'Box'  A super big pain to discover and code around.

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    When you click on the object, does another UI appear, similar to a drop down combo box?

    Drop down showing items Blue and Green

     

    • hina's avatar
      hina
      Contributor

      Hi rraghvani,

      Thank you for your reply. Below is my UI:

      I am trying to click "TestComplete Work Area 1", that's when I see the error I reported. When  I click "TestComplete Work Area 1", the Dataset list on right side shows up.

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        I'm assuming the Datasets is not populated until the Work Areas item is selected first? If that is the case, then you need to wait for the child item Datasets object to exist, before proceeding to the next step.

        If you use the Object Browser, you should be able to see the behaviour of how your object is created.

        I'm using Browser App as an example - you have the following item .Panel(6).Panel(0).Button("dropdownMenuButton") which represents the button 'Dropdown button'. However, the child item .Panel(6).Panel(0).Panel(0) does not exist yet (shown in red).When you click on the button 'Dropdown button', the child item .Panel(6).Panel(0).Panel(0) is then created (shown in blue). You can then access the object afterwards.

        Use the appropriate WaitNNN methods to wait for the child object to appear first. 

  • The error indicates that the object wasn't ready for interaction at the time the action was attempted. The test log often includes a screenshot, which can provide helpful visual context on the state of the UI at the failure point. https://support.smartbear.com/testcomplete/docs/testing-with/running/handling-errors/searching-for-cause.html 

    Here are a few targeted suggestions:

    1. Use VisibleOnScreen and Enabled Together along with Width and Height
    if (obj.VisibleOnScreen && obj.Enabled && obj.Width > 0 && obj.Height > 0) {
        obj.Click();
    } else {
        Log.Error("Object is not intractable at this time.");
    }
    

    You can also configure https://support.smartbear.com/testcomplete/docs/working-with/managing-projects/properties/visualizer.html or https://support.smartbear.com/testcomplete/docs/reference/test-objects/controls/misc/options/index.html Visualizer to capture object info

    // Set the option to "Capture images and test object info"
    Options.Visualizer.CollectMode = vcmImg;

    ๐Ÿค– AI-assisted response.
    ๐Ÿ’ฌ Found the answer helpful? Give it a Kudos by clicking Like!
    โœ… Got your issue resolved? Click Mark as Solution so others can find it quickly.

    • hina's avatar
      hina
      Contributor

      Hi Hassan,

      Thank you for you reply. I tried the following code as you suggested:

      function test2()
      {
        var WA = Sys["Process"]("AXISEL")["WinFormsObject"]("MainForm")["WinFormsObject"]("splitContainer1")["WinFormsObject"]("SplitterPanel", "", 1)["WinFormsObject"]("NavigationBar")["WinFormsObject"]("WorkAreaView")["WinFormsObject"]("TV")["OutlineItem"]("TestComplete Work Area 1*");
        WA["Refresh"]();
        Delay(1000);
        
        Log["Event"](WA.VisibleOnScreen);
        Log["Event"](WA.Enabled);
        Log["Event"](WA.Width);
        Log["Event"](WA.Height);
        
        WA["WaitProperty"]("VisibleOnScreen","True",2000);
        
        if (WA.VisibleOnScreen && WA.Enabled && WA.Width > 0 && WA.Height > 0) 
          WA.Click();
        else 
          Log.Error("Object is not interactable at this time.");

      }

      So at the time of clicking the object, the width and height is 0 and the property VisibleOnScreen is False, even though I can see the object on screen. After using Refresh method on the object multiple times, I can click the object. I tried using WaitProperty method as shown above in the code, but no use.

      • Hassan_Ballan's avatar
        Hassan_Ballan
        Icon for Champion Level 3 rankChampion Level 3

        It looks like the object isn't fully initialized when TestComplete tries to interact with it, even though itโ€™s visually present. This is common with complex WinForms UIs.

        Try using a polling loop with Refresh() and short delays, and also check parent container visibility. If the control is virtualized or delayed in rendering, this should help you synchronize interaction more reliably.

        Also consider using WaitChild() or FindChild() to ensure dynamic readiness, and try SetFocus() before clicking.

        // 1. Use WaitAliasChild or WaitChild Instead of Static Object References
        var WA = Sys.Process("AXISEL")
          .WinFormsObject("MainForm")
          .WinFormsObject("splitContainer1")
          .WinFormsObject("SplitterPanel", "", 1)
          .WinFormsObject("NavigationBar")
          .WinFormsObject("WorkAreaView")
          .WinFormsObject("TV")
          .WaitChild("OutlineItem", 5000);
        
        if (WA.Exists) {
          WA.Refresh();
          Delay(1000);
          // ...
        }
        
        // 2. Loop Until the Object Is Interactable
        var maxTries = 10;
        var success = false;
        
        for (var i = 0; i < maxTries; i++) {
          WA.Refresh();
          Delay(500);
        
          if (WA.VisibleOnScreen && WA.Enabled && WA.Width > 0 && WA.Height > 0) {
            success = true;
            break;
          }
        }
        
        if (success)
          WA.Click();
        else
          Log.Error("Object is still not interactable after multiple attempts.");
        
        // 3. Check for Parent Container Visibility
        var container = Sys.Process("AXISEL")
          .WinFormsObject("MainForm")
          .WinFormsObject("splitContainer1")
          .WinFormsObject("SplitterPanel", "", 1)
          .WinFormsObject("NavigationBar");
        
        Log.Message("Container visibility: " + container.VisibleOnScreen);
        
        // 4. Use SetFocus() Before Interaction
        WA.SetFocus();
        Delay(500);
        WA.Click();
        

        In some WinForms apps (especially with custom or third-party controls), elements like tree views use virtualization โ€” meaning TestComplete sees the node only when it's scrolled into view or selected.

        You might need to scroll or expand parent nodes, and use keyboard navigation if mouse-based visibility fails.

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    hinaโ€‹ have you tried using the appropriate WaitNNN methods to wait for the child object to to be created?

    From what your have mentioned with regards to property values, it seems like your object is not created. Therefore, you can not check the property values yet.

    • hina's avatar
      hina
      Contributor

      Hi rraghvani,

      Yes, I have tried WaitChild method, but no luck. The only thing that is working everytime is when I restart the application I am working with.

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        If you use the Object Browser (not Object Spy), is there any indication as to when the child object is created?

        Are you able to post a picture of the Object Browser, before and after object is created (similar to my example)?

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    I like Hassan_Ballanโ€‹ thought about a parent object issue.  I you run 

    FindAllChildren Method
    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findallchildren-method.html

    This will return, "An array of child objects that have the specified values of the specified properties."  That you can loop through and log properties that could affect access to the target option.

    Running this from strategic points in the object tree and check the properties of the returned object may provide some useful information. 

    The thought that refreshing from the root process may be working lends credibility to this thought.  Refreshing the entire app object tree is an expensive process that will slow down your tests so I would do this sparingly.  Your delays currently are pretty long so if you define the offending object you should be able to focus a wait on that parent object's desired state to dynamically wait and remove the long static delays.

    Good luck!  I'll keep following along.  .๐Ÿ˜Ž