cancel
Showing results for 
Search instead for 
Did you mean: 

how to check if an object is exits?

Highlighted
New Contributor

how to check if an object is exits?

I want to check if an object exists to check the page is displayed and access the object.

 

when the page is not displayed,  label in below code trowing exception and coming out, I have tried to check whether it is NULL before assigning to label, even that didn't work. how can this be achieved?

 

IDriver driver = new LocalDriver();

IWPFPopupMenuOwner label = driver.Find<IProcess>(new ProcessPattern() { ProcessName = "*****"
.Find<ITopLevelWindow>(new WinFormsPattern() { WinFormsControlName = "******" })
.Find<IWindow>(new WinFormsPattern() { ClrFullClassName = "System.Windows.Forms.MdiClient", WndCaption = "" })
.Find<ITopLevelWindow>(new WinFormsPattern() { WinFormsControlName = "****" })
.Find<IWindow>(new WinFormsPattern() { WinFormsControlName = "******" })
.Find<IWindow>(new WinFormsPattern() { WinFormsControlName = "*****" }
.Find<IWindow>(new WinFormsPattern() { WinFormsControlName = "*******" })
.Find<IWindow>(new WinFormsPattern() { WinFormsControlName = "*****" })
.Find<IWPFPopupMenuOwner>(new WPFPattern() { ClrFullClassName = "System.Windows.Documents.AdornerDecorator" }, 2)
.Find<IWPFPopupMenuOwner>(new WPFPattern() { WPFControlName = "****" }, 7);

1 REPLY 1
Highlighted
Community Hero

Re: how to check if an object is exits?

Hi,

 

As per https://support.smartbear.com/testleft/docs/using/creating-tests/searching-for-objects.html, .Find() method fails if the sought for object cannot be found. .TryFind() complimentary one should be used when the target object may not exist (yet).

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Labels