Casting repository items

Ask general questions here.
johnsmith
Posts: 18
Joined: Sun Mar 18, 2012 2:13 am

Casting repository items

Post by johnsmith » Sun Mar 18, 2012 2:39 am

Hello,

I have correctly tracked a WebDocument in the repository.
However if I try to change its type to WebDocument in its properties, it won't let me do so. I can see the WebDocument option in "adapter type", but once I click on it, it reverses to default. Why cannot I set its type?

Another question - how do I get a browser from that WebDocument programatically from code?

If I drop it from repository, I get code similar to the following:

Code: Select all

var myWebPage = repo...;
But I need it to be of WebDocument type in order to be able to do the following:

Code: Select all

if(myWebPage.BrowserName == "IE")  ...
Ranorex won't let me call .BrowserName, because myWebPage isn't of type WebDocument.

If I try to cast it the following way I will get a error:

Code: Select all

WebDocument myWebPage = (WebDocument)repo...;/code] 

How can I get browser from a WebDocument that's stored in a repository?

Thanks!

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

Re: Casting repository items

Post by Support Team » Mon Mar 19, 2012 1:17 pm

Hi,
johnsmith wrote:However if I try to change its type to WebDocument in its properties, it won't let me do so. I can see the WebDocument option in "adapter type", but once I click on it, it reverses to default. Why cannot I set its type?
You cannot change it because on a webdocument the default adapter is webdocument. Therefore it switches back to default.
johnsmith wrote:How can I get browser from a WebDocument that's stored in a repository?
You just have to call the repo item via the repo instance and call your webdocument by this instance.
var repo = YourRepo.Instance; //Instance of your repo           

if(repo.Google.Self.BrowserName == "IE") //Google is your webdocument
{
	Report.Info("Current browser is IE");
}
Regards,
Peter
Ranorex Team
.
Image

johnsmith
Posts: 18
Joined: Sun Mar 18, 2012 2:13 am

Re: Casting repository items

Post by johnsmith » Mon Mar 19, 2012 2:09 pm

Thanks, adding ".Self" to the repo item did the trick!