Forum Discussion

EmonsLucas's avatar
EmonsLucas
New Contributor
9 months ago

check if object .exists Error

Hello everyone,

I have the problem in my code, that when I want to check if my object exist to continue, he stops and give me this error log:

 

"Unable to find the following object when executing the WPFObject command:" "NameMapping.Sys.Logit_Dilos_WpfShell.HwndSource_Root.Root.ExternalApplicationTabs.pnl"

 

function LagerTestOpen(){
var TimeoutValue, startTime, HauptModul, ModulButton, ModulPanel;
startTime = new Date();
TimeoutValue = Options.Run.Timeout;
ModulPanel = NameMapping.Sys.Logit_Dilos_WpfShell.HwndSource_Root.Root.ExternalApplicationTabs.pnl.WaitWPFObject("TextBlock", "Lager", 1);
Funktionen.check_dilos_open();

if (ModulPanel.Exists) {
Log.Message("Das Modul Lager ist bereits geöffnet!");
} else {
HauptModul = Aliases.Logit_Dilos_WpfShell.HwndSource_Root.Root.menuItems.WPFObject("ListBoxItem", "", 1).WPFObject("StackPanel", "", 1).WPFObject("TextBlock", "Stammdaten", 1);
HauptModul.Click();

ModulButton = Aliases.Logit_Dilos_WpfShell.HwndSource_Root.Root.subMenuDataTree.WPFObject("XamDataTreeNodeControl", "", 5).WPFObject("StackPanel", "", 1).WPFObject("Button", "Lager", 1);
ModulButton.Click();

ModulPanel = NameMapping.Sys.Logit_Dilos_WpfShell.HwndSource_Root.Root.ExternalApplicationTabs.pnl.WaitWPFObject("TextBlock", "Lager", 1);
if (ModulPanel.Exists) {
Log.Message("Das Modul Lager wurde erfolgreich geöffnet!");
} else {
Log.Error("Das Modul Lager konnte nicht geöffnet werden!"); }
}

 

  • Yes, but you are using it on

    WaitWPFObject("TextBlock", "Lager", 1);

    which is ClassName and WndCaption.

     

    The error is relating to object pnl, which is what you need to check for.

5 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Insert code via this icon, so that it retains the format. Otherwise it's difficult to read.

     

    From what I can see in your code, you are trying to get the property value from an object and assigning it to ModulePanel.

     

    ModulPanel = NameMapping.Sys.Logit_Dilos_WpfShell.HwndSource_Root.Root.ExternalApplicationTabs.pnl.WaitWPFObject("TextBlock", "Lager", 1);

     

    However, pnl object may not exist, therefore you need to check if the object actually exists, before getting the property value. For example,

     

    if (NameMapping.Sys.Logit_Dilos_WpfShell.HwndSource_Root.Root.ExternalApplicationTabs.pnl.Exists)

     

    ...each parent object must exist i.e. ExternalApplication, Root, HwndSource_Root etc

    • EmonsLucas's avatar
      EmonsLucas
      New Contributor
      Hey thanks for your reply,
      i added the code.
      My goal is to check if the module has already been opened based on the panel that appears when the module is open in the application. If this panel is present, there's no issue because it means that it has found it and, therefore, gives the message that it's already open. However, if it's not open, it throws the described error. But I want it to recognize that the object doesn't exist, and I can continue the code with 'if object not exists.' I hope you can understand me a bit :)"
    • EmonsLucas's avatar
      EmonsLucas
      New Contributor

      I tried this method, in my Code you can see i have the WaitWPFObject method

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Yes, but you are using it on

    WaitWPFObject("TextBlock", "Lager", 1);

    which is ClassName and WndCaption.

     

    The error is relating to object pnl, which is what you need to check for.