two way to use findsingle

Class library usage, coding and language questions.
User avatar
taoyang987
Posts: 19
Joined: Sun Jan 06, 2013 8:43 am

two way to use findsingle

Post by taoyang987 » Thu Jan 24, 2013 7:22 am

i offen see two ways to use "findSingle" one like this :

Code: Select all

Button button = form.FindSingle<Ranorex.Button>(".//button[@controlid='132']"); 
othe other is

Code: Select all

Button button = form.FindSingle(".//button[@controlid='132']"); 
i usually use the second one .
what's the diffence?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: two way to use findsingle

Post by Support Team » Thu Jan 24, 2013 3:02 pm

Hi,

FindSingle<T>(RxPath): Applies a Ranorex Path to the adapter, returning a specific adapter type (e.g. Role or Capability).
FindSingle(RxPath): Applies a Ranorex Path to the adapter, returning an Element.

In your case the returning Element, of the second method, is type casted to Button.
With the second method you could also use this code:
Element element = form.FindSingle(".//button[@controlid='132']"); 
Report.Info(element.Role.ToString());
Button button = element.As<Button>();

Regards,
Markus
.
Image

User avatar
taoyang987
Posts: 19
Joined: Sun Jan 06, 2013 8:43 am

Re: two way to use findsingle

Post by taoyang987 » Fri Jan 25, 2013 1:42 am

Thanks,Markus