Forum Discussion

Ali2's avatar
Ali2
Occasional Contributor
2 months ago
Solved

I want to ignore unable to find object error, how do i do that??

function closetabs(){ var tabContainer = NameMapping.Sys.TRAFiX.HwndSource_MainWindow1.MainWindow1_.dockLayoutManager.mainlayoutGroup.mainDocumentGroup; var totalTabs = 10; // Assuming there are 10...
  • Hassan_Ballan's avatar
    2 months ago

    I would suggest that you make updates to your script
    1.Remove the if Exists
    2.Replace the for loop with a while Exists loop (this also would eliminate the need to specify the number of tabs)

    Also the if Exists will wait for the default timeout of 10 seconds before proceeding, so you will need to change the default time out and restore it back when done.

    I have not tried this modified code but should give you the idea.

    function closetabs()
    {
      var tabContainer = NameMapping.Sys.TRAFiX.HwndSource_MainWindow1.MainWindow1_.dockLayoutManager.mainlayoutGroup.mainDocumentGroup;
    
      // Change default timeout from x seconds to one second
      var TimeoutValue;
      TimeoutValue = Options.Run.Timeout;
      Options.Run.Timeout = 1000;
      
      // Use while exists loop 
      var tab = tabContainer.WPFObject("DocumentPaneItem", "", 1); // Always use first tab
      while(tab.Exists == true)
        tab.Click(tab.Width-10,tab.Height/2);
        var tab = tabContainer.WPFObject("DocumentPaneItem", "", 1); // Always use first tab
      
      // Restore default timeout back to x seconds
      Options.Run.Timeout = TimeoutValue;
    }