Issues with .Exists()

Class library usage, coding and language questions.
Murphy
Posts: 5
Joined: Wed Nov 30, 2011 6:07 pm

Issues with .Exists()

Post by Murphy » Wed Nov 30, 2011 6:17 pm

I am running into some issues with testing for the existence of a webpage.

Code: Select all

public void Login()
    	{
    		bool bExists;

    		bExists = repo.pgLogin.SelfInfo.Exists();

    		if(bExists)
    		{
    			repo.pgLogin.txtUsername.Value = this.sUsername;
    			repo.pgLogin.txtPassword.Value = this.sPassword;
    			repo.pgLogin.btnLogin.Click();
    		}
    		else
    		{
    			Validate.Exists(repo.pgLogin.SelfInfo);
    		}    		
    	} 
- The webpage(pgLogin) is open when this code is run through.

The call to "repo.pgLogin.SelfInfo.Exists();" is returning false which causes the code to go into the "else" statement. But in there, the "Validate.Exists(repo.pgLogin.SelfInfo);" is passing and says the "Element for item 'Self' does exist." in the log. I am completely stumped as to why this is happening.

Couple notes:
- When in the repository, the Highlight Element option finds the page with no issues.
- If I change the first .Exists() call to a Validate.Exists(), it fails

Any ideas?

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

Re: Issues with .Exists()

Post by Support Team » Wed Nov 30, 2011 6:59 pm

Hi,

as described in code examples, the Exists() method is looking for the item until the repository timeout is over.

Within the Validate.Exists, the same thing as above is happening.

Explanation for repository search timeout: For each repository item, there is a Search Timeout defined. If an action or a code is using this item, Ranorex will look for this item for the time which is defined as timeout for this item.
As soon as the item is there, Ranorex will do the action on it.

Therefore, it could be that Exists() won't find the item but Validate.Exists(..) finds the item.
E.g. if the repository timeout for repo.pgLogin is 5seconds, Exists() is looking for it for 5 seconds, and Validate.Exists() is doing the same thing - if the item exists after 8 seconds, Exists() won't find it but Validate.Exists(..) will find it.

Now your solution might be to increase this timeout for the repo.pgLogin element. Do this via clicking right on the item in the repository and selection properties from the context menu.
Now the properties for the item are displayed on the right side. Change the Search Timeout to a bigger value.

Best Regards,
Martin
Ranorex Support Team
.
Image

Murphy
Posts: 5
Joined: Wed Nov 30, 2011 6:07 pm

Re: Issues with .Exists()

Post by Murphy » Wed Nov 30, 2011 7:13 pm

That fixed the problem, thanks!