Page 1 of 2

.Exists not working Properly

Posted: Mon Apr 07, 2014 10:51 am
by Deepak_Singh
Hi All,

I am doing scripting and using .Exists to check whether the User Is Logged in or not, If not then Perform a Login.
But the problem is when user is not logged then the Scripts run Properly but when the .Exists fails then it does not go to Else ststement instead it gives error regarding "Element not found".
Please Help.


The code is below:

Code: Select all

var repo = TrailRepository.Instance;
            
            if(repo.Explorer.LoginInfo.Exists())
            {	var Login = repo.Explorer.Login;
            	Report.Info("Login","User Already Logged in!!!");
            	Delay.Milliseconds(1000);
            }
            else
            {
            	Report.Info("Login","Not Logged");
            }
            if(repo.Explorer.LogoutInfo.Exists())
            {
            	var Logout = repo.Explorer.Logout;
            	Logout.DoubleClick();
            	var text1001 = repo.Login.Text1001;
            	text1001.Click();
            	Delay.Milliseconds(100);
            	text1001.PressKeys("{Delete}");
            	text1001.PressKeys("Test");
            	Delay.Milliseconds(1000);
            	var text7003 = repo.Login.Text7003;
            	text7003.Click();
            	Delay.Milliseconds(100);
            	text7003.PressKeys("Test@123");
            	Delay.Milliseconds(1000);
            	var buttonOK = repo.Login.ButtonOK;
            	buttonOK.Click();
            	Delay.Milliseconds(100);
            }
            
            else
            {
            	Report.Info("Hi","Not Logged On");
            }
            
Thanks,
Deepak

Re: .Exists not working Properly

Posted: Wed Apr 09, 2014 12:15 pm
by mzperix
Hi,

I tried to look in the API documentation, but I did not find anything about the Info class's Exist() method, so I have to guess:

repo.Explorer.LoginInfo.Exists() does not return false (as we would expect), when the element does not exist, but rather it throws an exception.

So try to change the if-else statements to try-catch statements.

Hope this helps,

Best Regards,
Zoltán Major

Re: .Exists not working Properly

Posted: Wed Apr 09, 2014 1:33 pm
by krstcs
Exists() returns TRUE if the element for the item exists, and FALSE if it does not. However, it will attempt to find the item for the entire time of the SearchTimeout value for the item and all parents.

The exception you are getting is probably due to another issue. If you post the report and a snapshot we might be able to help you figure it out.

Re: .Exists not working Properly

Posted: Thu Apr 10, 2014 12:57 pm
by Deepak_Singh
Hi,

This is now serious. I think its the IF statement which is having the problems.
I removed the .exist and used .visible property.
Still same error If the if statement is true then ok but if the If statement is false then still it is trying to search for the element and giving Error.

Please help ASAP.

Regards,
Deepak :(

Re: .Exists not working Properly

Posted: Thu Apr 10, 2014 1:21 pm
by mzperix
Hi,

You can try it out, just make a new project and look for a single element if it exists or not.

I just did a small project, and used usercode and codemodule. Both is running fine for me. Write to ranorex support, and send them any information you could, like project itself and a snapshot.

Regards,
Zoltán

Re: .Exists not working Properly

Posted: Thu Apr 10, 2014 1:38 pm
by krstcs
Make sure that the parent object is also existing/visible. This is likely the issue.

Ranorex Spy is your friend. Use it to check the whole path.

Re: .Exists not working Properly

Posted: Fri Apr 11, 2014 10:12 am
by Deepak_Singh
Hi All,

I found what was creating problems.

If you drag and drop the object from the Repository and after that check for the existence of the object.
In this scenario if the object is Present then the Test will run without any problem, but if the object is not present still Ranorex tries to find the object and throws an error saying "object not found".

Solution: First check for the existence with "repo.objectInfo.exists()"and if found then declare the variable(drag and drop the object from the Repository) and then use it.
"Worked for me" :lol:

Regards,
Deepak :D

Re: .Exists not working Properly

Posted: Wed Apr 16, 2014 9:00 pm
by Deepak_Singh
Hi All,

2 things i need to ask.

1: .exists property checks whether the object is available or not. If object exists then fine but if its not available then ranorex instead of going into Else statement tries to find the object for 1.5 mins and then goes into Else statement. This delays my test case execution a lot so is there a way to reduce this time???

2:When i write Delay.Millisecond(60000)
then ranorex waits for 60 seconds. If the next page gets loaded then still it waits for completion of the time. Apart from Shift+Pause which is manual cant we do it in some way that ranorex waits till the whole page is loaded so this Delay dependency is not there.

For Ex: we have in qtp browser.page .sync
here sync method waits for full page to load by itself without any manual hardcoding in the script.

Thanks in Advance,
Deepak

Re: .Exists not working Properly

Posted: Thu Apr 17, 2014 4:10 pm
by mzperix
Hi Deepak,

1. set the timeout property of the element, and the element's parent (there should be 2 more parent levels, since every level adds 30 sec to the effective timeout).

To set a repository elements searchtimeout to 1 sec try this:

Code: Select all

repo.Ranorexwebpage.SearchTimeout=1000;
2. The delay is working as intended, it just waits all the time. For waiting a page to load, try waitfordocumentloaded: http://www.ranorex.com/Documentation/Ra ... Loaded.htm

Here is an another forum topic about document reload: http://www.ranorex.com/forum/waitfordoc ... t1057.html

Best Regards,
Zoltán

Re: .Exists not working Properly

Posted: Mon Apr 21, 2014 8:19 am
by Deepak_Singh
Hi Zoltan,

This means I have to write this for every object or Just add page into the Repository and write and it will work for all the objects in that page?

Regards,
Deepak

Re: .Exists not working Properly

Posted: Tue Apr 22, 2014 1:14 pm
by mzperix
Hi Deepak,

Unfortunately you have to set the timeout for every element.

If you set the page's timeout to 1 sec, then all of the elements on the page will have a timeout of 31 sec.

You can set the default timeout of NEWLY created elements to a custom value in the Settings page.

For the elements already in repository, you can just use a text editor (I use notepad++), and do a search&replace for timeout.


Hope I am clear,

Best regards,
Zoltan

Re: .Exists not working Properly

Posted: Tue Apr 22, 2014 1:52 pm
by Deepak_Singh
Hi Zoltan,

Adding wait for every element!!! :?
Not a good option and not a good Automation practice I think.

Another Question:
Is there any method or predefined function in Ranorex that waits for the page to load all the objects?

Like .sync is present in QTP ?

Regards,
Deepak

Re: .Exists not working Properly

Posted: Tue Apr 22, 2014 11:34 pm
by mzperix
Hi Deepak,

Do you use web pages, desktop application or a mobile application?

If you are using webpages, try first with WebDocument.WaitForDocumentLoaded(), described here: http://www.ranorex.com/Documentation/Ra ... Loaded.htm

If this is not working, or you are using other technologies, then use the usual stuff:
Wait for elements to appear, or wait for elements to disappear. Set a high enough timeout for those elements, and the waiting is solved :)

Regards,
Zoltan

Re: .Exists not working Properly

Posted: Wed Apr 23, 2014 11:21 am
by Deepak_Singh
Ok Will Try that,

One More question. Can we perform a Long click on an object?
If yes then how? :?:

Regards,
Deepak

Re: .Exists not working Properly

Posted: Wed Apr 23, 2014 11:58 am
by mzperix
Hi Deepak,

How can you click long? :)

See Mouse class: http://www.ranorex.com/Documentation/Ra ... _Mouse.htm

among the methods is the Mouse.Click(MouseButtons, Duration): http://www.ranorex.com/Documentation/Ra ... ick_28.htm

The duration will tell how much time should elapse between mouse down and mouse up.

Hope this helps,
Zoltan

P.S. Look into the Ranorex API: http://www.ranorex.com/Documentation/Ranorex/ It helps you is looking for the actions that QTP has also. And for everything else, there is .NET :)