ClassHtmlControl
Base class for all HtmlControl's.
Definition
Namespace:ArtOfTest.WebAii.Controls.HtmlControls
Assembly:ArtOfTest.WebAii.dll
Syntax:
public class HtmlControl : Control
Inheritance: objectControlHtmlControl
Derived Classes:
Inherited Members
Constructors
HtmlControl(Element)
Wrap the specified Element into a new HtmlControl.
Properties
Attributes
All attributes defined for this HtmlControl.
Declaration
public virtual ReadOnlyCollection<iAttribute> Attributes { get; }
Property Value
ReadOnlyCollection<iAttribute>
A ReadOnlyCollection<iAttribute> of the attributes defined for this HtmlControl.
ChildNodes
Get all the child element nodes of this HtmlControl.
Declaration
public ReadOnlyCollection<Element> ChildNodes { get; }
Property Value
A ReadOnlyCollection of the child Element's of this HtmlControl.
ClientSideLocator
Gets the client-side locator for this HtmlControl. This property can be used to define a custom client side object that this HtmlControl maps to. GetValue/SetValue properties use that object to make their calls instead of the default one.
Declaration
public virtual string ClientSideLocator { get; }
Property Value
A string identifying the locator for this HtmlControl.
Example
(in ASP.NET) $find('myClientObject')
CssClass
This HtmlControl's CSS class name.
Declaration
public virtual string CssClass { get; }
Property Value
A string specifying this HtmlControl's CSS class name. An empty string if not present for this HtmlControl
Remarks
See also http://msdn.microsoft.com/en-us/library/ms533560(VS.85).aspx
Events
The list of events defined on this HtmlControl
Declaration
public virtual NameValueCollection Events { get; }
Property Value
A NameValueCollection containing a list of events defined on this HtmlControl. An empty list is returned if there are no styles defined.
Find
Find property
GetElementByIdClientSideLocator
Returns the getElementByIdName script with ShadowDom support
Declaration
protected string GetElementByIdClientSideLocator { get; }
Property Value
GetElementByTagNameClientSideLocator
Returns the getElementByTagName script with ShadowDom support
Declaration
protected string GetElementByTagNameClientSideLocator { get; }
Property Value
ID
This HtmlControl's ID.
Declaration
public virtual string ID { get; }
Property Value
A string specifying this HtmlControls ID. An empty string if not present for this HtmlControl.
IsActiveElement
Gets whether this element has the keyboard focus
IsEnabled
Gets / sets whether this control is enabled (not disabled)
Declaration
public bool IsEnabled { get; set; }
Property Value
Remarks
Only applies to input controls
Mappings
Gets a mappings collection that stores customizable control specific mapping knowledge that can be later customized.
Declaration
public virtual MappingsCollection Mappings { get; }
Property Value
ScrollLeft
Gets / Sets the scrollLeft value of this HtmlControl.
Declaration
public virtual int ScrollLeft { get; set; }
Property Value
An int specifying the scrollLeft value.
ScrollTop
Gets / Sets the scrollTop value of this HtmlControl.
Declaration
public virtual int ScrollTop { get; set; }
Property Value
An int specifying the scrollTop value for this HtmlControl.
Styles
Styles collection set on this HtmlControl and persisted in the Html stream. This collection does not contain computed styles.
Declaration
public virtual NameValueCollection Styles { get; }
Property Value
A NameValueCollection containing a list of styles defined on this HtmlControl. An empty list is returned if there are no styles defined.
TagName
The tag name of this HtmlControl.
Declaration
public virtual string TagName { get; }
Property Value
A string specifying the tag identification of this HtmlControl.
Methods
AddEventListener(string, EventHandler<JavascriptEventArgs>)
Add an event handler to a Javascript event handler list on this HtmlControl.
Declaration
public virtual bool AddEventListener(string eventType, EventHandler<JavascriptEventArgs> listener)
Parameters
eventType
The event type to add the handler to.
listener
EventHandler<JavascriptEventArgs>
The event handler to add.
Returns
True/False indicating whether or not the event handler was successfully added.
AsjQueryControl()
Convert this HtmlControl to jQueryControl.
AssignElement(Element)
Attach the specified Element to this HtmlControl and initialize its internal properties.
CallMethod(string)
Call a client side Javascript method on this HtmlControl.
Declaration
public void CallMethod(string methodCall)
Parameters
methodCall
The method call.
CallMethod<T>(string)
Call a client side Javascript method on this HtmlControl and return type T.
Declaration
public virtual T CallMethod<T>(string methodCall)
Parameters
methodCall
The method call string.
Returns
T
The return value from the methoc call, if any
CallMethod<T>(string, T)
Call a client side Javascript method on this HtmlControl with return type of T and a default return value.
Declaration
public virtual T CallMethod<T>(string methodCall, T defaultValue)
Parameters
methodCall
The method call string.
defaultValue
T
A default value to use in case the conversion failed to the specified type and you want to return a custom default value other than default(T).
Returns
T
The return value of the call or the default value.
Capture()
Captures and returns a bitmap image of this HtmlControl.
Capture(string)
Captures and saves this HtmlControl's image to the WebAii log location as a Bitmap file.
Declaration
public virtual void Capture(string imageName)
Parameters
imageName
The image file name (without extension) to create and write to.
Capture(string, string)
Captures and saves this HtmlControl's image to the specified save path as the specified file name as a Bitmap file.
Click(bool)
Invoke a click on this HtmlControl that will cause its browser window to close (this is common for html pop-ups).
Declaration
public virtual void Click(bool isClosing)
Parameters
isClosing
If set, we won't wait for the browser to be ready. If not set it acts the same as HtmlControl.Click().
Download(bool, DownloadOption, string, int)
Clicks a control using the MouseClick or Click and handles the download dialogs sequence that is produced.
Declaration
public virtual void Download(bool clickUsingDesktopMouse, DownloadOption downloadOption, string saveLocation, int downloadTimeout)
Parameters
clickUsingDesktopMouse
When set to True Desktop Mouse.Click will be used. Make sure the HtmlControl is visible in the browsers window first before using Desktop Mouse.Click. When set to False HtmlControl.Click will be used.
downloadOption
The download option to use (Save or Cancel).
saveLocation
The save location on disk when the download option is set to Save.
downloadTimeout
The number of milliseconds to wait until all download dialogs are handled.
Exceptions
Timed out waiting for the download dialogs to be handled.
DragTo(HtmlControl)
Drag this HtmlControl to the center on the destination HtmlControl.
Declaration
public virtual void DragTo(HtmlControl control)
Parameters
control
The destination HtmlControl
DragTo(HtmlControl, OffsetReference, Point)
Drag to a destination HtmlControl with an offset of where within the destination HtmlControl to drag to.
Declaration
public virtual void DragTo(HtmlControl control, OffsetReference destinationOffsetReference, Point destinationOffset)
Parameters
control
The destination HtmlControl.
destinationOffsetReference
The destination offset reference.
destinationOffset
The offset amount from destination reference. May be positive or negative.
DragTo(OffsetReference, Point, HtmlControl)
Drag this HtmlControl by specifying a reference point on the HtmlControl rectangle to start the drag from with an offset and drop on the destination HtmlControl center.
Declaration
public virtual void DragTo(OffsetReference sourceOffsetReference, Point sourceOffset, HtmlControl destination)
Parameters
sourceOffsetReference
The source offset reference of the drag start.
sourceOffset
The offset from the specified source reference. May be positive or negative.
destination
The destination HtmlControl.
DragTo(OffsetReference, Point, HtmlControl, OffsetReference, Point)
Drag this HtmlControl by specifying a reference point on the HtmlControl rectangle to start the drag from and a reference point on the destination HtmlControl to specify the drop location.
Declaration
public virtual void DragTo(OffsetReference sourceOffsetReference, Point sourceOffset, HtmlControl destination, OffsetReference destinationOffsetReference, Point destinationOffset)
Parameters
sourceOffsetReference
The source offset reference of the drag start.
sourceOffset
The offset from the specified spirce reference. May be positive or negative.
destination
The destination HtmlControl.
destinationOffsetReference
The destination offset reference of the drop.
destinationOffset
The offset from the specified destination reference. May be positive or negative.
DragTo(OffsetReference, Point, int, int)
Drag this HtmlControl from a source offset to an X/Y offset from the source.
Declaration
public virtual void DragTo(OffsetReference sourceOffsetReference, Point sourceOffset, int destinationOffsetX, int destinationOffsetY)
Parameters
sourceOffsetReference
The source offset reference.
sourceOffset
The source offset.
destinationOffsetX
The destination X offset relative to the source.
destinationOffsetY
The destination Y offset relative to the source.
DragTo(OffsetReference, int, int, Rectangle, OffsetReference, int, int)
Drag this HtmlControl from a source offset to an X/Y offset from the source.
Declaration
public virtual void DragTo(OffsetReference sourceOffsetReference, int sourceOffsetX, int sourceOffsetY, Rectangle destinationRectangle, OffsetReference destinationOffsetReference, int destinationOffsetX, int destinationOffsetY)
Parameters
sourceOffsetReference
The source offset reference.
sourceOffsetX
The X offset from the source. May be positive or negative.
sourceOffsetY
The Y offset from the source. May be positive or negative.
destinationRectangle
destinationOffsetReference
The destination rectangle reference.
destinationOffsetX
The X offset from the destination.
destinationOffsetY
The Y offset from the destination.
DragTo(OffsetReference, int, int, bool, HtmlControl, OffsetReference, int, int, bool)
Drag this HtmlControl by specifying a reference point on the HtmlControl rectangle to start the drag from and a reference point on the destination HtmlControl to specify the drop location.
Declaration
public virtual void DragTo(OffsetReference sourceOffsetReference, int sourceOffsetX, int sourceOffsetY, bool sourcePixelDrag, HtmlControl destination, OffsetReference destinationOffsetReference, int destinationOffsetX, int destinationOffsetY, bool pixelDrop)
Parameters
sourceOffsetReference
The source offset reference of the drag start.
sourceOffsetX
The offset X from the specified source reference. May be positive or negative.
sourceOffsetY
The offset Y from the specified source reference. May be positive or negative.
sourcePixelDrag
If True, will use the sourceOffsetX and sourceOffsetY as the pixel drop point, if false will use sourceOffsetX and sourceOffsetY as a percentage for calculating the drop point.
destination
The destination HtmlControl.
destinationOffsetReference
The destination offset reference of the drop.
destinationOffsetX
The offset X from the specified destination reference. May be positive or negative.
destinationOffsetY
The offset Y from the specified destination reference. May be positive or negative.
pixelDrop
If True, will use the windowOffsetX and windowOffsetY as the pixel drop point, if false will use windowOffsetX and windowOffsetY as a percentage for calculating the drop point.
DragTo(Point)
Drag this HtmlControl to an absolute screen coordinate point.
Declaration
public virtual void DragTo(Point absolutePoint)
Parameters
absolutePoint
The absolute screen coordinate point.
DragTo(int, int)
Drag this HtmlControl to a relative X/Y offset.
DragToWindowLocation(OffsetReference, int, int, bool, OffsetReference, int, int, bool)
Drag this HtmlControl, using the browser window as the drop target
Declaration
public virtual void DragToWindowLocation(OffsetReference sourceOffsetReference, int sourceOffsetX, int sourceOffsetY, bool sourcePixelDrag, OffsetReference windowOffset, int windowOffsetX, int windowOffsetY, bool pixelDrop)
Parameters
sourceOffsetReference
The source offset reference of the drag start.
sourceOffsetX
The offset X from the specified source reference. May be positive or negative.
sourceOffsetY
The offset Y from the specified source reference. May be positive or negative.
sourcePixelDrag
If True, will use the sourceOffsetX and sourceOffsetY as the pixel drop point, if false will use sourceOffsetX and sourceOffsetY as a percentage for calculating the drop point.
windowOffset
The destination offest reference of the drag destination.
windowOffsetX
The offset X from the specified destination reference. May be positive or negative.
windowOffsetY
The offset Y from the specified destination reference. May be positive or negative.
pixelDrop
If True, will use the windowOffsetX and windowOffsetY as the pixel drop point, if false will use windowOffsetX and windowOffsetY as a percentage for calculating the drop point.
FindParentContainer<TContainerControl>()
Traverses the DOM tree upwards until it finds the container element desired.
Declaration
protected Element FindParentContainer<TContainerControl>() where TContainerControl : HtmlContainerControl, new()
Returns
The container element or element null.
GetAttributeAsString(string)
Get an attribute of this element as a string
GetComputedStyle(string)
Returns an HtmlStyle object that can be used to easily probe the style value. (i.e. convert unit styles to Int32 or color value to System.Drawing.Color)
GetComputedStyleValue(string)
Returns the computed value of the specified style. The computed style value represents the final computed value taking into account the CSS properties for this HtmlElement.
GetRectangle()
The absolute screen position and size of this HtmlControl.
GetStyle(string)
Returns a HtmlStyle object that can be used to easily probe the style value. (i.e. convert unit styles to Int32 or color value to System.Drawing.Color)
GetStyleValue(string)
Returns any style as if you are accessing the element.style object from JavaScript.
GetValue<T>(string)
Get a property value (e.g. control.border or control.style.backgroundColor).
Declaration
public virtual T GetValue<T>(string propertyName)
Parameters
propertyName
The property name.
Returns
T
The value of the property or default(T) if the value of the property cannot be retrieved or converted to type T.
Remarks
The property is retrieved by executing Javascript on the client side using the specified property name as the Javascript function.
Example
string s = myControl.GetValue<string>("style.backgroundColor")
GetValue<T>(string, T)
Get a property value (e.g. control.border or control.style.backgroundColor) and return the specified default value if the get fails for any reason.
Declaration
public virtual T GetValue<T>(string propertyName, T defaultValue)
Parameters
propertyName
The property name.
defaultValue
T
A default value to use in case the conversion failed to the specified type and you want to return a custom default value other than default(T).
Returns
T
The value of the property or defaultValue if the property value cannot be retrieved or converted.
Remarks
The property is retrieved by executing Javascript on the client side using the specified property name as the Javascript function.
Example
string s = myControl.GetValue<string>("style.backgroundColor", "White")
GetValue<T>(string, bool)
Get a property value (e.g. control.border or control.style.backgroundColor) with ability to specify wrappedJSObject's in Firefox.
Declaration
[Obsolete]
public virtual T GetValue<T>(string propertyName, bool isJsWrappedObject)
Parameters
propertyName
The property name.
isJsWrappedObject
Only applies to Firefox browser. Set to true to indicate this HtmlControl is a wrappedJSObject.
Returns
T
The value of the property.
Remarks
The property is retrieved by executing Javascript on the client side using the specified property name as the Javascript function.
Example
string s = myControl.GetValue<string>("style.backgroundColor", true)
GetValue<T>(string, bool, T)
Get a property value (e.g. control.border or control.style.backgroundColor) with ability to specify wrappedJSObject's in Firefox and return the specified default value if the get fails for any reason.
Declaration
[Obsolete]
public virtual T GetValue<T>(string propertyName, bool isJsWrappedObject, T defaultValue)
Parameters
propertyName
The property name.
isJsWrappedObject
Only applies to Firefox browser. Set to true to indicate this HtmlControl is a wrappedJSObject.
defaultValue
T
The return value, if the property has no value (is null or the empty string)
Returns
T
The value of the property.
Remarks
The property is retrieved by executing Javascript on the client side using the specified property name as the Javascript function.
Example
string s = myControl.GetValue<string>("style.backgroundColor", true, "White")
InitializeMappings(MappingsCollection)
Initialize the Mappings collection. This method is called when the Mappings collection is accessed for the first time. It is then cached
Declaration
public virtual void InitializeMappings(MappingsCollection mappings)
Parameters
mappings
The mappings collection to populate
InvokeEvent(ScriptEvent)
Invokes an event on this HtmlControl.
Declaration
public virtual void InvokeEvent(ScriptEvent eventObj)
Parameters
eventObj
An object representing the event to invoke
InvokeEvent(ScriptEvent, bool)
Invokes an event on this HtmlControl.
Declaration
public virtual void InvokeEvent(ScriptEvent eventObj, bool closesBrowser)
Parameters
eventObj
An object representing the event to invoke
closesBrowser
If set, we won't wait for the browser to be ready. If not set it acts the same as HtmlControl.InvokeEvent(eventObj).
InvokeEvent(ScriptEventType)
Invokes an event on this HtmlControl.
Declaration
public virtual void InvokeEvent(ScriptEventType eventType)
Parameters
eventType
The ScriptEventType to invoke.
InvokeEvent(ScriptEventType, bool)
Invokes an event on this HtmlControl.
Declaration
public virtual void InvokeEvent(ScriptEventType eventType, bool closesBrowser)
Parameters
eventType
The ScriptEventType to invoke.
closesBrowser
If set, we won't wait for the browser to be ready. If not set it acts the same as HtmlControl.InvokeEvent(eventObj).
IsVisible()
Returns whether the html element is visible or not. Returns true only when computedStyle.display != 'none' && computedStyle.visibility != 'hidden'
Declaration
public virtual bool IsVisible()
Returns
True/False indicating whether or not this HtmlControl is currently visible on the page.
MouseClick()
Uses the Desktop.Mouse object to move the mouse to this HtmlControl and click it.
Declaration
public virtual void MouseClick()
MouseClick(MouseClickType)
Uses the Desktop.Mouse object to move the mouse to the absolute center of this HtmlControl and simulate a left mouse click. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseClick(MouseClickType clickType)
Parameters
clickType
Mouse Click Type
MouseClick(MouseClickType, Point, OffsetReference)
Uses the Desktop.Mouse object to move the mouse to a point relative to this HtmlControl and simulate the specified mouse click. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseClick(MouseClickType clickType, Point offset, OffsetReference reference)
Parameters
clickType
One of the MouseClickType types.
offset
A point relative to the reference specified to click. The x and/or y values may be negative.
reference
Which point on the HtmlControl is used as the reference point.
MouseClick(MouseClickType, int, int)
Uses the Desktop.Mouse object to move the mouse to a point relative to this HtmlControl and simulate the specified mouse click. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseClick(MouseClickType clickType, int x, int y)
Parameters
clickType
One of the MouseClickType types
x
The X offset relative to the left edge of the control to click. May be negative.
y
The Y offset relative to the top side of the control to click. May be negative.
MouseClick(MouseClickType, int, int, OffsetReference)
Uses the Desktop.Mouse object to move the mouse to a point relative to this HtmlControl and simulate the specified mouse click. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseClick(MouseClickType clickType, int Xoffset, int Yoffset, OffsetReference reference)
Parameters
clickType
One of the MouseClickType types.
Xoffset
The X offset relative to the specified reference to click. May be negative.
Yoffset
The Y offset relative to the specified reference to click. May be negative.
reference
Which point on the HtmlControl is used as the reference point.
MouseHover()
Uses the Desktop.Mouse object to Hover over this absolute center of this HtmlControl. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseHover()
MouseHover(Point)
Uses the Desktop.Mouse object to Hover over a point relative to this HtmlControl. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseHover(Point pointToHoverOver)
Parameters
pointToHoverOver
Point relative to the upper left corner of this HtmlControl to hover. X and/or Y value may be negative.
MouseHover(int, int)
Uses the Desktop.Mouse object to Hover over a point relative to this HtmlControl. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
MouseHover(int, int, OffsetReference)
Uses the Desktop.Mouse object to Hover over a point relative to this HtmlControl. Be sure this HtmlControl is visible in the browser window first. Call ScrollToVisible(ScrollToVisibleType) or ScrollToVisible(ScrollToVisibleType, Rectangle)first if the element could be currently outside of the browsers window.
Declaration
public virtual void MouseHover(int x, int y, OffsetReference reference)
Parameters
x
The X offset relative to the specified reference to hover over. May be negative.
y
The Y offset relative to the specified reference to hover over. May be negative.
reference
Which point on the HtmlControl is used as the reference point.
Parent<TContainerControl>()
Return the parent HtmlContainerControl of the desired type that this HtmlControl is contained inside of. If a parent HtmlControl of the desired type is not found, will return null.
Declaration
public virtual TContainerControl Parent<TContainerControl>() where TContainerControl : HtmlContainerControl, new()
Returns
TContainerControl
The parent container HtmlControl or null if desired type is not found.
ParseResponseValue<T>(string, T)
Declaration
protected T ParseResponseValue<T>(string response, T defaultValue)
Parameters
response
defaultValue
T
Returns
T
RemoveEventListener(string, EventHandler<JavascriptEventArgs>)
Removes an event handler from a Javascript event handler list on this HtmlControl.
Declaration
public virtual void RemoveEventListener(string eventType, EventHandler<JavascriptEventArgs> listener)
Parameters
eventType
The event type to be remove the event handler from.
listener
EventHandler<JavascriptEventArgs>
The event handler to remove.
ScrollToVisible()
Scroll the browsers window to make this HtmlControl visible on the page. This will method uses the ScrollToVisibleType.ElementTopAtWindowTop
Declaration
public virtual void ScrollToVisible()
ScrollToVisible(ScrollToVisibleType)
Scroll the browsers window to make this HtmlControl visible on the page.
Declaration
public virtual void ScrollToVisible(ScrollToVisibleType scrollToVisibleType)
Parameters
scrollToVisibleType
How the HtmlControl should be aligned on the page
ScrollToVisible(ScrollToVisibleType, Rectangle)
Scroll the browsers window so that the specified rectangle within this HtmlControl is visible on the page.
Declaration
public virtual void ScrollToVisible(ScrollToVisibleType scrollToVisibleType, Rectangle rectangle)
Parameters
scrollToVisibleType
How the HtmlControl should be aligned on the page.
rectangle
The rectangular portion of the HtmlControl that we want to make sure is visible on the page.
SetValue<T>(string, T)
Set a property value. (e.g. control.border = 2 or control.style.backgroundColor = "red")
Declaration
public virtual void SetValue<T>(string propertyName, T value)
Parameters
propertyName
The property name.
value
T
The value to set.
Example
myControl.SetValue$lt;string>("style.backgroundColor","red")
SetValue<T>(string, T, bool)
Set a property value. (e.g. control.border = 2 or control.style.backgroundColor = "red") myControl.SetValue<string>("style.backgroundColor","red")
Declaration
public virtual void SetValue<T>(string propertyName, T value, bool isJsWrappedObject)
Parameters
propertyName
The property name.
value
T
The value to set.
isJsWrappedObject
Whether the property is a JsWrappedObject. Specific to Firefox.
Example
myControl.SetValue<string>("style.backgroundColor","red")
ToString()
Builds and returns a string representation of this element.
Declaration
public override string ToString()
Returns
A string representation of this element.
Overrides
ValidateControl()
Validate a HtmlControl using its LocatorExpression.
Declaration
protected bool ValidateControl()
Returns
true of the control validated successfully. Otherwise false.
Exceptions
Thrown when the control does not match its FindExpression.
Remarks
ValidateControl uses LocatorExpression if both LocatorExpression and Locator are defined, and uses Locator only if LocatorExpression is not defined.
ValidateTag(string)
Validate a tag name