Class Element
Represents an UI item in the global UI tree. Instances of this class dynamically implement a Role and optional Capabilities, as well as numerous standard properties.
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Element : MarshalByRefObject, IElement, ISerializable
- Inheritance
-
Element
- Implements
- Inherited Members
Constructors
Element(SerializationInfo, StreamingContext)
For Ranorex internal use only. Initializes a new instance of the Element class.
[Browsable(false)]
protected Element(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoThe serialization information.
contextStreamingContextThe streaming context.
Properties
Actions
A list of actions the element supports. This list is aggregated from the role and the capabilities.
[Browsable(false)]
[TypeConverter(typeof(CollectionConverter))]
public IList<ActionDescriptor> Actions { get; }
Property Value
Attributes
A list of attributes the element supports. This list is aggregated from the role and the capabilities.
[Browsable(false)]
[TypeConverter(typeof(CollectionConverter))]
public IList<AttributeDescriptor> Attributes { get; }
Property Value
Capabilities
The list of the capabilities the element has.
[Browsable(false)]
[TypeConverter(typeof(CollectionConverter))]
public IList<Capability> Capabilities { get; }
Property Value
ChildIndex
The index of this element in the parent's child list. Is '-1' if the index is unknown.
public int ChildIndex { get; }
Property Value
Children
The list of children the element has.
[Browsable(false)]
[TypeConverter(typeof(CollectionConverter))]
public IList<Element> Children { get; }
Property Value
ClientRectangle
The bounding rectangle of the element, relative to the parent.
public Rectangle ClientRectangle { get; }
Property Value
DynamicCapability
Gets a capability providing dynamic attributes and actions that the element supports.
public Capability DynamicCapability { get; }
Property Value
Enabled
True if the element is enabled.
public bool Enabled { get; }
Property Value
FlavorElement
The flavor element associated with the element. This can be null, for example when using static snapshots.
[Browsable(false)]
public FlavorElement FlavorElement { get; }
Property Value
FlavorName
The name of the flavor this element belongs to.
public string FlavorName { get; }
Property Value
HasFocus
True if the element has the focus.
public bool HasFocus { get; }
Property Value
IsRemote
Gets a value indicating whether the element resides on a remote device.
[Browsable(false)]
public bool IsRemote { get; }
Property Value
- bool
trueif this instance resides on a remote device; otherwise,false.
IsSnapshot
Gets a value indicating whether this instance is a snapshot.
[Browsable(false)]
public bool IsSnapshot { get; }
Property Value
- bool
trueif this instance is a snapshot; otherwise,false.
this[string]
Indexer for attribute access.
public object this[string name] { get; set; }
Parameters
namestringName of the attribute to return.
Property Value
- object
The value of the attribute.
Limitations
Gets a list of technology specify limitations that are associated with this element.
[Browsable(false)]
[TypeConverter(typeof(CollectionConverter))]
public IList<TechnologyLimitation> Limitations { get; }
Property Value
Remarks
The list implementation checks for duplicates and null entries and does not
add/insert such entries.
Location
The location of the element, relative to its parent.
public Point Location { get; }
Property Value
Parent
The parent of the element.
[Browsable(false)]
[TypeConverter(typeof(ExpandableObjectConverter))]
public Element Parent { get; }
Property Value
Remarks
Is null if the element is a root element.
PreferredCapability
The preferred capability of the element.
public Capability PreferredCapability { get; }
Property Value
Remarks
Usually, this is the role, but it can be any of the capabilities. This property is used when building RxPaths.
Role
The role of the element (= main capability).
public Role Role { get; }
Property Value
ScreenLocation
The location of the element in screen coordinates.
public Point ScreenLocation { get; }
Property Value
ScreenRectangle
The bounding rectangle of the element in screen coordinates.
public Rectangle ScreenRectangle { get; }
Property Value
Size
The (x,y) size of element.
public Size Size { get; }
Property Value
TopLevelAncestor
The top-level ancestor of the element.
[Browsable(false)]
[TypeConverter(typeof(ExpandableObjectConverter))]
public Element TopLevelAncestor { get; }
Property Value
Remarks
Is null if the element is a root element.
Valid
Returns true if the element is believed to be valid.
public bool Valid { get; }
Property Value
Visible
True if the element is visible.
public bool Visible { get; }
Property Value
Remarks
Note that even if the element is visible, it might be covered by another visible element.
Methods
As<T>()
Returns an adapter of the specified type for the element.
public T As<T>() where T : Adapter
Returns
- T
The specified adapter for the element or
nullif the element does not provide the capabilities required for the adapter.
Type Parameters
TThe adapter type. The supplied type must inherit from Adapter, but most not be the Adapter type itself.
CaptureCompressedImage()
Captures a PNG image of the element.
public CompressedImage CaptureCompressedImage()
Returns
- CompressedImage
A compressed image of the element.
EnsureVisible()
Tries to make the element visible to the user. This is usually accomplished by bringing the element or one of its ancestors to foreground.
public bool EnsureVisible()
Returns
- bool
True if the operation has succeeded.
Equals(Element, Element)
Returns true if the two instances are considered equal.
public static bool Equals(Element a, Element b)
Parameters
Returns
- bool
Trueif the two instances are equal, otherwisefalse.
Equals(object)
Compares the element to an object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare to.
Returns
- bool
True if obj and the element are the same.
Find(RxPath)
Applies a Ranorex Path to the element.
public IList<Element> Find(RxPath path)
Parameters
Returns
Exceptions
- ArgumentNullException
If
pathisnull.
Find(RxPath, Duration)
Applies a Ranorex Path to the element.
public IList<Element> Find(RxPath path, Duration timeout)
Parameters
pathRxPathThe RxPath to apply.
timeoutDurationThe time to keep looking for at least one element matching the path.
Returns
Exceptions
- ArgumentNullException
If
pathisnull.
FindFromPoint(Point)
Find an element by screen location. The found element is a descendant of this instance or this instance itself.
public Element FindFromPoint(Point screenLocation)
Parameters
screenLocationPointThe location where the element is located.
Returns
- Element
The element at the specified location or null if nothing was found.
Remarks
This method requires a Ranorex Professional/Premium license.
FindFromPoint(Point, out RxPath)
Find an element by screen location and build its RxPath. The found element is a descendant of this instance or this instance itself.
public Element FindFromPoint(Point screenLocation, out RxPath resultPath)
Parameters
screenLocationPointThe location where the element is located.
resultPathRxPathThe result RxPath.
Returns
- Element
The element at the specified location or null if nothing was found.
Remarks
This method requires a Ranorex Professional/Premium license.
FindFromUid(string, out Element)
Finds a descendant element by its unique identifier attribute (defined by the owner flavor UidAttribute name).
public bool FindFromUid(string uidValue, out Element result)
Parameters
Returns
- bool
Returns
trueif an element was found for the given unique id value.
Remarks
For this to work, the underlying flavor element has to implement GetChildLineageFromUid() and has to set IsUidDomainRoot properly.
FindSingle(RxPath)
Applies a Ranorex Path to the element.
public Element FindSingle(RxPath path)
Parameters
Returns
- Element
The first element found.
Exceptions
- ArgumentNullException
If
pathisnull.- ElementNotFoundException
If no element is found.
FindSingle(RxPath, Duration)
Applies a Ranorex Path to the element.
public Element FindSingle(RxPath path, Duration timeout)
Parameters
Returns
- Element
The first element found.
Exceptions
- ArgumentNullException
If
pathisnull.- ElementNotFoundException
If no element is found within the timeout.
Focus()
Tries to set the focus on the element.
public void Focus()
FromPath(string)
Converts a string to an element instance by searching the root.
public static Element FromPath(string path)
Parameters
pathstringThe search path.
Returns
- Element
The result element.
Remarks
The DefaultSearchTimeout is used to search for the specified path.
Exceptions
- ArgumentNullException
If
pathisnull.- ElementNotFoundException
If no element is found.
- RxPathException
If the specified
pathis not valid.
GetAttributeValue(string)
Returns the value of an attribute.
public object GetAttributeValue(string name)
Parameters
namestringThe name of the attribute.
Returns
- object
The value of the attribute.
Exceptions
- ArgumentNullException
If
nameisnull.
GetAttributeValueText(string)
Returns the value of an attribute converted to its string representation.
public string GetAttributeValueText(string name)
Parameters
namestringThe name of the attribute.
Returns
- string
The value of the attribute converted to its string representation.
Remarks
This method internally calls GetAttributeValue(string) and converts the returned value to its string representation using the ValueConverter.
Exceptions
- ArgumentNullException
If
nameisnull.
GetAttributeValueText(string, Regex)
Returns the value of an attribute converted to its string representation. If a regex
is provided, only the part of the string representation matching the regular
expression is returned.
public string GetAttributeValueText(string name, Regex regex)
Parameters
namestringThe name of the attribute.
regexRegexA regular expression that defines which part of the attribute value string representation should be returned. If more than a single group (= whole match) is captured by the regex, the second group (mark using "(?<1>expression)") is returned.
Returns
- string
The value of the attribute converted to its string representation and optionally matched by the provided
regexregular expression.
Remarks
This method internally calls GetAttributeValue(string) and converts the returned value to its string representation using the ValueConverter.
Exceptions
- ArgumentNullException
If
nameisnull.
GetHashCode()
Default implementation override.
public override int GetHashCode()
Returns
- int
The object hash code.
GetObjectData(SerializationInfo, StreamingContext)
For Ranorex internal use only. Populates a SerializationInfo with the data needed to serialize the target object.
[Browsable(false)]
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoThe SerializationInfo to populate with data.
contextStreamingContextThe destination (see StreamingContext) for this serialization.
GetPath(PathBuildMode)
Builds an absolute RxPath to the element.
public RxPath GetPath(PathBuildMode buildMode)
Parameters
buildModePathBuildModeSpecifies how the path should be built. (optimization vs. runtime tradeoff)
Returns
- RxPath
The path of the element.
GetPath(PathBuildMode, Element)
Builds an RxPath to the element, relative to another element.
public RxPath GetPath(PathBuildMode buildMode, Element relativeToElement)
Parameters
buildModePathBuildModeSpecifies how the path should be built. (optimization vs. runtime tradeoff)
relativeToElementElementThe element to which the path is relative to.
Returns
- RxPath
The path of the element.
GetRobustPath()
Builds an absolute RxPath to the element.
public RxPath GetRobustPath()
Returns
- RxPath
The path of the element.
HasCapability(string)
Tests if the element possesses a certain capability (or role), by name.
public bool HasCapability(string capName)
Parameters
capNamestringThe name of the capability to look for.
Returns
- bool
True if the element has the capability or role.
InvokeAction(string, params object[])
Invokes an action on the element.
public object InvokeAction(string name, params object[] args)
Parameters
Returns
- object
The invocation result.
Remarks
The types of the parameters and return value are as defined by the ActionDescriptor.
Exceptions
- ArgumentNullException
If
nameisnull.- ActionFailedException
Thrown if invoking the action failed.
InvokeActionWithText(string, params string[])
Invokes an action on the element.
public object InvokeActionWithText(string name, params string[] args)
Parameters
namestringThe name of the action to invoke.
argsstring[]The list of parameters for the action, as strings.
Returns
- object
The invocation result.
Remarks
The string values of the parameters are converted to the types defined by the ActionDescriptor.
Exceptions
- ArgumentNullException
If
nameisnull.- ActionFailedException
Thrown if invoking the action failed, or argument type conversion failed.
IsAncestor(Element)
Determines whether the current element is an ancestor of the specified child element.
public bool IsAncestor(Element child)
Parameters
childElementThe child element to test.
Returns
- bool
trueif the this element is an ancestor; otherwise,false.
IsEqual(Element)
Compares two elements by comparing their flavor elements or their screen rectangles if no flavor comparison is possible.
public bool IsEqual(Element elem)
Parameters
elemElementThe element to compare to.
Returns
- bool
True if the elements are equal.
SetAttributeValue(string, object)
Sets the value of an attribute.
public void SetAttributeValue(string name, object value)
Parameters
Exceptions
- ArgumentNullException
If
nameisnull.- SetAttributeFailedException
Thrown if setting the attribute value failed.
SetAttributeValue(string, string)
Sets the value of an attribute.
public void SetAttributeValue(string name, string value)
Parameters
Exceptions
- ArgumentNullException
If
nameisnull.- SetAttributeFailedException
Thrown if setting the attribute value failed or the string value could not be converted to the attribute's type.
ToString()
public override string ToString()
Returns
TryFindSingle(RxPath, out Element)
Tries to apply a Ranorex Path to the element.
public bool TryFindSingle(RxPath path, out Element foundElement)
Parameters
pathRxPathThe RxPath to apply.
foundElementElementThe first element found or
nullif no element is found.
Returns
- bool
Trueif an element is found for the specifiedpath, otherwisefalse.
TryFindSingle(RxPath, Duration, out Element)
Tries to apply a Ranorex Path to the element.
public bool TryFindSingle(RxPath path, Duration timeout, out Element foundElement)
Parameters
pathRxPathThe RxPath to apply.
timeoutDurationThe time to keep looking for the element.
foundElementElementThe first element found or
nullif no element is found within the timeout.
Returns
- bool
Trueif an element is found for the specifiedpathwithin the specifiedtimeout, otherwisefalse.
Operators
implicit operator Element(string)
Implicitly converts a string to an element instance by searching the root.
public static implicit operator Element(string path)
Parameters
pathstringThe search path.
Returns
- Element
The result element.
Remarks
The DefaultSearchTimeout is used to search for the specified path.
Exceptions
- ArgumentNullException
If
pathisnull.- ElementNotFoundException
If no element is found.
- RxPathException
If the specified
pathis not valid.