Handling objects

Class library usage, coding and language questions.
kris123pra
Posts: 16
Joined: Fri Sep 17, 2010 8:13 am
Location: India

Handling objects

Post by kris123pra » Sun Oct 31, 2010 3:17 pm

Hi

I have a workflow, where we expect that as per the input given there might be a error message displayed or the workflow might just go on.

Say, if there is a image open functionality which takes image string as input. If the image is valid, then it shall be opened and some operations are performed. But if it is a invalid image, there would be a error dialog displayed.

In my case, I had used RxPath in the code. It works fine if the object is found, but throws an error if not found, which is known. But I would like to know if we can handle this dynamically and no error is thrown.

Here is the code snippet:

Code: Select all

try{
Ranorex Form formError = "/form[@title='Error'];
if (formError.Visible)
  <click on ok>
   <return>
else
  <open image>
  <do some operations on image>
   <return>
}
catch(Exception e)
{
report.error(e.ToString());
}
This throws a error if a valid image is passed, since the formError is not found. Can anyone please suggest what can be done here? :roll:

Thanks
Kris

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Handling objects

Post by artur_gadomski » Mon Nov 01, 2010 9:01 am

Try:
formErrorInfo.Exists()
or
formError.SelfInfo.Exists()
they should not throw exception when form is not found. Drawback is that your automation will be put on hold for however long it will look for that form (default is 10 sec). You might want to read:
http://www.ranorex.com/blog/handling-di ... up-windows
to detect this form in a separate thread.

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

Re: Handling objects

Post by Support Team » Mon Nov 01, 2010 3:33 pm

Hi,

An additional option would be to use the TryFindSingle() Method which returns you a boolean value. With this value you can handle you decision and actions by code. But I would suggest you the same as artur_gadomski to read the following blog http://www.ranorex.com/blog/handling-di ... up-windows

Regards,
Peter
Ranorex Team
.
Image

kris123pra
Posts: 16
Joined: Fri Sep 17, 2010 8:13 am
Location: India

Re: Handling objects

Post by kris123pra » Wed Nov 10, 2010 11:21 am

Hi
Since I am working on i18n, I use my own repository. I dont know how to use the selfInfo.exists() method.

I tried using the TryFindSingle and it worked. Thanks !
Though this works for now, since I have lots of such different pop ups (errors, warnings), I would like to know if I can use the .Exists method too :|

Thanks :)
Kris

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

Re: Handling objects

Post by Support Team » Wed Nov 10, 2010 3:27 pm

Hi,

Normally there shouldn't be a problem to use the Exists() method. Take a look to following post http://www.ranorex.com/forum/selecting- ... html#p6282
I also used the Exists() method to check if an item is available. Would it be possible to send us an example application with your automation code, where we can reproduce this issue. Maybe it's just a wrong code.

Thanks in advance.

Regards,
Peter
Ranorex Team
.
Image

kris123pra
Posts: 16
Joined: Fri Sep 17, 2010 8:13 am
Location: India

Re: Handling objects

Post by kris123pra » Mon Nov 29, 2010 4:44 am

Hi
I used the code given in
http://www.ranorex.com/forum/how-to-val ... t1047.html
This seems to be neater and works fine for my code.

I would have been happy to put my code here, but I am not supposed to do that as per company policies. So here is a explanation of how my code works :)

As I said before, I do not use the repository generated by Ranorex, but have a code which dynamically generates the RXpath as per the language selected. So I have no freedom of using <something>Info.Exists() method.

Anyways, now that I have something working .. thanks a lot for all the support :D Regards
Kris