Page 1 of 1

child class is not inheriting property from parent

Posted: Fri Nov 01, 2013 12:41 pm
by rkarhe
Hello,

I have created wrapper of Ranorex.WebElement something like below.

namespace WObject
{
public class WWebElement : Ranorex.WebElement
{
public WWebElement()
: base()
{
}

public WWebElement(Element element)
: base(element)
{
}

public static implicit operator WWebElement(string path)
{
return new WWebElement(path);
}

public static implicit operator WWebElement(Ranorex.Core.Element element)
{
return new WWebElement(element);
}
}
}

When I am using this wrapper like below

WObject.WWebElement controlToEdit = ele.As<WObject.WWebElement>().NextSibling;

it says Cannot implicitly convert type 'Ranorex.WebElement' to 'WObject.WWebElement'. An explicit conversion exists (are you missing a cast?)

Looks like "ele.As<WObject.WWebElement>().NextSibling" is returning parent element (whereas I think it should return child.)

What is the problem here? Why not child 'WObject.WWebElement' has inherited property '.NextSibling'?

Thanks in advance...

Re: child class is not inheriting property from parent

Posted: Sun Nov 03, 2013 12:57 am
by rkarhe
Any suggestion on this.
I have tried redefining in child like "new public WWebElement NextSibling { get; set; }"
but this returns null object and not next element.

WObject.WWebElement controlToEdit = ele.As<WObject.WWebElement>().NextSibling;
//controlToEdit is null when tried redefining NextSibling in child class.

Also I should not need to Redefine this way in child class or should I ? What's the use of inheritance then?

Thanks in advance...

Re: child class is not inheriting property from parent

Posted: Mon Nov 04, 2013 4:32 pm
by Support Team
rkarhe wrote:What is the problem here? Why not child 'WObject.WWebElement' has inherited property '.NextSibling'?
The NextSibling is indeed inherited (otherwise you could not call it :D ), but it returns a WebElement, not your newly defined class. So you need to use the As method again to get an instance of your specialized WWebElement adapter back. (Depending on what type the "ele" variable is, you might omit the first usage of the "As" method).
WObject.WWebElement controlToEdit = ele.As<WObject.WWebElement>().NextSibling.As<WObject.WWebElement>();
rkarhe wrote: have tried redefining in child like "new public WWebElement NextSibling { get; set; }"
In C#, what you did is not a "redefine", but a new property that is just named "NextSibling" and that hides the base property. Consequently, this new property will just stay "null" forever (unless you assign the property to some value).

Regards,
Alex
Ranorex Team