Class
Element

Represents an element in the Document Object Model (DOM) tree.

Definition

Namespace:ArtOfTest.WebAii.ObjectModel

Assembly:ArtOfTest.WebAii.dll

Syntax:

cs-api-definition
public class Element : ITargetElement

Inheritance: objectElement

Implements: ITargetElement

Constructors

Element(HtmlFindExpression, Find, Browser)

Initialize an element proxy. The only property off this element that you can use is Wait.Exist() or Wait.ExistsNot()

Declaration

cs-api-definition
public Element(HtmlFindExpression findExpr, Find findObj, Browser ownerBrowser)

Parameters

findExpr

HtmlFindExpression

A FindExpression identifying this element

findObj

Find

The Find object to use

ownerBrowser

Browser

Owner browser

Properties

AbsoluteSiblingTagIndex

Gets the absolute sibling tag index of this element within the parent node. Basically the order of this node among its siblings. Zero-based.

Declaration

cs-api-definition
public int AbsoluteSiblingTagIndex { get; set; }

Property Value

int

AbsoluteTagIndex

Gets the absolute that index of this element. This index is unique within a document.

Declaration

cs-api-definition
public int AbsoluteTagIndex { get; }

Property Value

int

Attributes

Gets the list of attributes defined for this element.

Declaration

cs-api-definition
public ReadOnlyCollection<iAttribute> Attributes { get; }

Property Value

ReadOnlyCollection<iAttribute>

ChildNodes

Gets the list of all parsed element of this tag including text literals, comments, malformed tags...etc.

Declaration

cs-api-definition
public ReadOnlyCollection<Element> ChildNodes { get; }

Property Value

ReadOnlyCollection<Element>

Children

Gets the list of child elements that are well formed markup non-text elements.

Declaration

cs-api-definition
public ReadOnlyCollection<Element> Children { get; }

Property Value

ReadOnlyCollection<Element>

Content

Gets the raw content of the tag that represents this element.

The following tag <foo id="bar" height="px">some text</foo> , has a Content property that is:

'<foo id="bar" height="px">'

Note: this does not include the innerText or the closing tag.

Declaration

cs-api-definition
public string Content { get; }

Property Value

string

CssClassAttributeValue

Gets the value of the attribute ('class') if present on this tag.

Declaration

cs-api-definition
public string CssClassAttributeValue { get; }

Property Value

string

Data

Gets/Sets any custom data associated with this element.

Declaration

cs-api-definition
public object Data { get; set; }

Property Value

object

Depth

Gets the hierarchical depth of this element

Declaration

cs-api-definition
public int Depth { get; }

Property Value

int

Implements ITargetElement.Depth

ElementType

Gets the element type (div, table ..etc).

Declaration

cs-api-definition
public ElementType ElementType { get; }

Property Value

ElementType

FindExpressionUsed

Gets the FindExpression used to find this element when using the Find object. This property is not set when calling the Find.Allxxx methods.

Declaration

cs-api-definition
[Browsable(false)]
public HtmlFindExpression FindExpressionUsed { get; }

Property Value

HtmlFindExpression

FindObjectUsed

Gets a reference to the Find object used to find this element

Declaration

cs-api-definition
[Browsable(false)]
public Find FindObjectUsed { get; }

Property Value

Find

FrameElement

Gets / Sets the root frame element that this element is contained in.

Declaration

cs-api-definition
public Element FrameElement { get; set; }

Property Value

Element

HasIdOrName

Gets whether this element has an id or a name set on it.

Declaration

cs-api-definition
public bool HasIdOrName { get; }

Property Value

bool

True/False whether or not this element has an ID or a Name attribute applied to it.

Host

Get the IAutomationHost associated with this element.

Declaration

cs-api-definition
public IAutomationHost Host { get; }

Property Value

IAutomationHost

Implements ITargetElement.Host

IdAttributeValue

Gets the value of the attribute ('id') if present on this tag.

Declaration

cs-api-definition
public string IdAttributeValue { get; }

Property Value

string

InnerMarkup

Gets the InnerMarkup of this element.

Example:

<foo id="1">hello<bar></bar></foo>

If foo is this element then InnerMarkup=<bar></bar>

Declaration

cs-api-definition
public string InnerMarkup { get; }

Property Value

string

InnerText

Gets this element's inner text content including all of its nested children.

Example:

<foo id="1">one<bar>two</bar></foo>

If foo is this element then InnerText=onetwo

Declaration

cs-api-definition
public string InnerText { get; }

Property Value

string

InputElementType

Gets the Input type (i.e. checkbox, radio...etc) if the ElementType=Input. Otherwise, will return NotSet.

Declaration

cs-api-definition
public InputElementType InputElementType { get; }

Property Value

InputElementType

IsBeginTag

Gets whether it is a begin tag <foo bar='me'> .

Declaration

cs-api-definition
public bool IsBeginTag { get; }

Property Value

bool

IsEndTag

Gets whether this element is an end tag </foo>.

Declaration

cs-api-definition
public bool IsEndTag { get; }

Property Value

bool

IsProxy

Gets whether this element is a proxy element or a fully initialized element.

Declaration

cs-api-definition
[Browsable(false)]
public bool IsProxy { get; }

Property Value

bool

IsSelfClosing

Gets whether the element is self-closing (<foo />).

Declaration

cs-api-definition
public bool IsSelfClosing { get; }

Property Value

bool

IsTestRegion

Gets whether the element is a test region or not. This function has been added for performance reasons. We don't want to call the ElementType property since it will trigger the full initialization of types.

Declaration

cs-api-definition
public bool IsTestRegion { get; }

Property Value

bool

Implements ITargetElement.IsTestRegion

MatchingClosingTag

Gets the element's closing tag if it is a begin tag and not self-closing.

Declaration

cs-api-definition
public Element MatchingClosingTag { get; set; }

Property Value

Element

NameAttributeValue

Gets the value of the attribute ('name') if present on this tag

Declaration

cs-api-definition
public string NameAttributeValue { get; }

Property Value

string

OuterMarkup

Gets the OuterMarkup of this element.

Example:

<foo id="1"><bar></bar></foo>

If foo is this element then outerMarkup=<foo id="1"><bar></bar></foo>

Declaration

cs-api-definition
public string OuterMarkup { get; }

Property Value

string

OwnerBrowser

Gets the owner browser of this element.

Declaration

cs-api-definition
[Browsable(false)]
public Browser OwnerBrowser { get; }

Property Value

Browser

Parent

Gets the Parent element.

Declaration

cs-api-definition
public Element Parent { get; }

Property Value

Element

ParsedElement

Returns the raw parsed element.

Declaration

cs-api-definition
public ParsedElement ParsedElement { get; }

Property Value

ParsedElement

The raw parsed element

Implements ITargetElement.ParsedElement

ParsingType

Gets the parsing type set by the parser. (Markup, LiteralText, Comment..etc)

Declaration

cs-api-definition
public ParsedElementType ParsingType { get; }

Property Value

ParsedElementType

TagName

Gets the tagName of the the element

Declaration

cs-api-definition
public string TagName { get; }

Property Value

string

TagNameIndex

Gets the tagName occurrence of this element.

If this element is TagName='foo', then TagNameIndex= 3 indicates that this element represents the third occurence of tagName 'foo' within this document.

Declaration

cs-api-definition
public int TagNameIndex { get; }

Property Value

int

TechnologyType

Get the technology type.

Declaration

cs-api-definition
public TechnologyType TechnologyType { get; }

Property Value

TechnologyType

Implements ITargetElement.TechnologyType

TextContent

Gets this element's inner text content without recursing through all its nested children for text.

Declaration

cs-api-definition
public string TextContent { get; }

Property Value

string

Wait

Gets the wait object to wait for certain conditions of this element.

Declaration

cs-api-definition
[Browsable(false)]
public Wait Wait { get; }

Property Value

Wait

Methods

AddChild(Element)

Add a child element to this element.

Declaration

cs-api-definition
public virtual void AddChild(Element child)

Parameters

child

Element

The child to add.

Remarks

This method will only add elements of ParsingType=Markup to the Children collection. ChildNodes collection will contain a complete list of elements of all types. (i.e. Comment,TextLiteral ...etc).

AddChildNode(ITargetElement)

Add this node as a child node.

Declaration

cs-api-definition
public void AddChildNode(ITargetElement element)

Parameters

element

ITargetElement

The element to add as a child

Implements ITargetElement.AddChildNode(ITargetElement)

As<TControl>()

Returns this elements as a strongly-typed control of type TControl.

Declaration

cs-api-definition
public TControl As<TControl>() where TControl : Control, new()

Returns

TControl

The control object.

Capture()

Captures the image of current element.

Declaration

cs-api-definition
public Bitmap Capture()

Returns

Bitmap

The image of current element.

Implements ITargetElement.Capture()

CaptureImage()

Captures the image of curent element with scaling and OS information.

Declaration

cs-api-definition
public ElementImage CaptureImage()

Returns

ElementImage

ElementsImageData object of curent Element

Implements ITargetElement.CaptureImage()

CastIncludingAncestors<TControl>(int)

Checks the current element and its ancestors for specified control and returns a strongly-typed control of type TControl.

Declaration

cs-api-definition
public TControl CastIncludingAncestors<TControl>(int depth = 5) where TControl : Control, new()

Parameters

depth

int

Maximum number of ancestor to check.

Returns

TControl

The control object.

ContainsAttribute(iAttribute, bool, StringComparison, bool)

Whether a certain attribute is contained in this element

Declaration

cs-api-definition
public bool ContainsAttribute(iAttribute attribute, bool usePartialAttributeValue, StringComparison comparison, bool matchQuotes)

Parameters

attribute

iAttribute

The attribute to compare.

usePartialAttributeValue

bool

Whether to use partinal values of the attribute values.

comparison

StringComparison

Comparison type.

matchQuotes

bool

Whether to match the quotes or not. This only applied when UsePartialAttributeValue is false.

Returns

bool

True/False Whether the attribute is contained or not.

ContainsAttribute(string)

True/False whether this element contains a specific attribute name.

Declaration

cs-api-definition
public bool ContainsAttribute(string attributeName)

Parameters

attributeName

string

The attribute name to check for.

Returns

bool

True/False on the attribute existence.

CreateLight(string, int)

Create an Element object with a specific tagname and index.

Declaration

cs-api-definition
public static Element CreateLight(string tagName, int tagIndex)

Parameters

tagName

string

The tagName

tagIndex

int

The tagIndex

Returns

Element

A lightweight element of the specified tag name and index.

Equals(object)

Defines how two Elements should be compared.

Declaration

cs-api-definition
public override bool Equals(object obj)

Parameters

obj

object

The object to compare.

Returns

bool

True/False whether the two objects are equal.

Overrides object.Equals(object)

Focus()

Give this element keyboard focus

Declaration

cs-api-definition
public void Focus()

FriendlyName()

Constructs a friendly name that represents this element.

Declaration

cs-api-definition
public string FriendlyName()

Returns

string

The string representation of this element.

GetAttribute(string)

Find a specific attribute by name and returns it. (case-insensitive)

Declaration

cs-api-definition
public iAttribute GetAttribute(string name)

Parameters

name

string

The name of the attribute to get.

Returns

iAttribute

The attribute or null if the attribute was not found.

GetAttribute(string, bool)

Finds a specific attribute name in the Element list of attributes and returns its object

Declaration

cs-api-definition
public iAttribute GetAttribute(string name, bool ignoreCase)

Parameters

name

string

The name of the attribute to find.

ignoreCase

bool

Ignore case when searching.

Returns

iAttribute

The attribute object or null if the attribute is not found.

GetAttributeValueOrEmpty(string)

Gets the value of the attribute or a String.Empty if attribute does not exist.

Declaration

cs-api-definition
public string GetAttributeValueOrEmpty(string attrName)

Parameters

attrName

string

The attribute to get.

Returns

string

String.Empty if not found, else the attribute name.

GetChildren()

Get the children of this node.

Declaration

cs-api-definition
public ITargetElement[] GetChildren()

Returns

ITargetElement[]

The list of children as an array.

Implements ITargetElement.GetChildren()

GetHashCode()

Get the hash code for this Element.

Declaration

cs-api-definition
public override int GetHashCode()

Returns

int

The hash code.

Overrides object.GetHashCode()

GetHostParent()

Returns the FRAME or IFRAME element containing this element's document, if one exists.

Declaration

cs-api-definition
public ITargetElement GetHostParent()

Returns

ITargetElement

The parent IFrame element this element is hosted in.

Implements ITargetElement.GetHostParent()

GetNextSibling()

Get the next sibling of this node. If this node is the last sibling, will return null.

Declaration

cs-api-definition
public Element GetNextSibling()

Returns

Element

The next sibiling.

GetParent()

Get the parent of this node.

Declaration

cs-api-definition
public ITargetElement GetParent()

Returns

ITargetElement

The parent node.

Implements ITargetElement.GetParent()

GetPreservedInnerText(bool)

Same as InnerText but will respect any whitespaces between the tags.

Declaration

cs-api-definition
public string GetPreservedInnerText(bool trimStartEnd)

Parameters

trimStartEnd

bool

True/False whether to trim the whitespace from the start/end of the string.

Returns

string

The preserved innertext.

GetPreviousSibling()

Get the previous sibiling of this node. If this node is the first sibling, will return null.

Declaration

cs-api-definition
public Element GetPreviousSibling()

Returns

Element

The previous sibling

GetRectangle()

Gets the element rectangle. (X,Y) and width, height as it appears on browser and screen. Takes into account any scrolling.

Declaration

cs-api-definition
public virtual Rectangle GetRectangle()

Returns

Rectangle

The rectangle object of this element.

Implements ITargetElement.GetRectangle()

GetStringPresentation()

Get the string representation of current element.

Declaration

cs-api-definition
public string GetStringPresentation()

Returns

string

The string representation of current element.

Implements ITargetElement.GetStringPresentation()

GetTextContentRecursive(params string[])

Gets the text content of this element, recursing only into the listed tags

Declaration

cs-api-definition
public string GetTextContentRecursive(params string[] tags)

Parameters

tags

string[]

The tags to recurse into

Returns

string

The combined test content of the specified tags.

GetUniqueHashCode()

Calculates the hash code for this element.

Declaration

cs-api-definition
public int GetUniqueHashCode()

Returns

int

The hash code.

Implements ITargetElement.GetUniqueHashCode()

GetValue<T>(string)

Get a property value on this element.

Declaration

cs-api-definition
public virtual T GetValue<T>(string propertyName)

Parameters

propertyName

string

The property name.

Returns

T

The property value returned as type T.

GetValue<T>(string, T)

Get a property value on this element.

Declaration

cs-api-definition
public virtual T GetValue<T>(string propertyName, T defaultValue)

Parameters

propertyName

string

The property name.

defaultValue

T

The return value, if the property has no value (is null or the empty string)

Returns

T

The property value returned as type T.

GetValue<T>(string, bool)

Get a property value on this element.

Declaration

cs-api-definition
[Obsolete]
public virtual T GetValue<T>(string propertyName, bool isJsWrappedObject)

Parameters

propertyName

string

The property name.

isJsWrappedObject

bool

True/False whether you are accessing an extended wrapperd JS object. [Needed for Firefox only]

Returns

T

The property value returned as type T.

GetValue<T>(string, bool, T)

Get a property value on this element.

Declaration

cs-api-definition
[Obsolete]
public virtual T GetValue<T>(string propertyName, bool isJsWrappedObject, T defaultValue)

Parameters

propertyName

string

The property name.

isJsWrappedObject

bool

True/False whether you are accessing an extended wrapped JS object. [Needed for Firefox only]

defaultValue

T

The return value, if the property has no value (is null or the empty string)

Returns

T

The property value returned as type T.

IsFrame()

Gets whether this element represents an iframe or frame

Declaration

cs-api-definition
public FrameInfo IsFrame()

Returns

FrameInfo

Return the FrameInfo of the frame if is a frame, else will return null

IsFrame(bool, bool)

Gets whether this element represents an iframe or frame

Declaration

cs-api-definition
public FrameInfo IsFrame(bool makeAbsolute, bool stripFinalBrowserSegment = false)

Parameters

makeAbsolute

bool

Whether to force the FrameInfo's Src to be an absolute URI

stripFinalBrowserSegment

bool

When used in conjunction with makeAbsolute, this will strip the final path segment from the owning browser's URL before concatenating the frame's src.

Returns

FrameInfo

Return the FrameInfo of the frame if is a frame, else will return null

Match(IFindExpression)

Match this expression against element.

Declaration

cs-api-definition
public bool Match(IFindExpression findExpr)

Parameters

findExpr

IFindExpression

The expression to use.

Returns

bool

Returns true/false

Implements ITargetElement.Match(IFindExpression)

Refresh()

Using the FindParamsUsed and the TestRegionIdUsed to find this element last, this methods will attempt to re-find this element in the new DOM tree.

Declaration

cs-api-definition
public virtual void Refresh()

Implements ITargetElement.Refresh()

Refresh(bool)

Using the FindParamsUsed and the TestRegionIdUsed to find this element last, this methods will attempt to re-find this element in the new DOM tree.

Declaration

cs-api-definition
public virtual void Refresh(bool forceDomTreeRefresh)

Parameters

forceDomTreeRefresh

bool

Force a Browser/Plugin refresh before attempting to refine this element.

SetClosingTag(ITargetElement)

Set the matching closing tag.

Declaration

cs-api-definition
public void SetClosingTag(ITargetElement closingElement)

Parameters

closingElement

ITargetElement

The closing tag

Implements ITargetElement.SetClosingTag(ITargetElement)

SetDepth(int)

Sets the hierarchical depth of this element.

Declaration

cs-api-definition
public void SetDepth(int depth)

Parameters

depth

int

The required depth

Implements ITargetElement.SetDepth(int)

SetParent(ITargetElement)

Sets the parent of this Element.

Declaration

cs-api-definition
public void SetParent(ITargetElement parent)

Parameters

parent

ITargetElement

The parent element.

Implements ITargetElement.SetParent(ITargetElement)

SetValue<T>(string, T)

Set a property to a value on this element.

Declaration

cs-api-definition
public virtual void SetValue<T>(string propertyName, T value)

Parameters

propertyName

string

The property name.

value

T

The value.

SetValue<T>(string, T, bool)

Set a property to a value on this element.

Declaration

cs-api-definition
public virtual void SetValue<T>(string propertyName, T value, bool isJsWrappedObject)

Parameters

propertyName

string

The property name.

value

T

The value.

isJsWrappedObject

bool

True/False whether you are accessing an extended wrapperd JS object. [Needed for Firefox only]

ToString()

String representation of an Element.

Declaration

cs-api-definition
public override string ToString()

Returns

string

The string representation.

Overrides object.ToString()

Extension Methods