Class WebElement
- Namespace
- Ranorex
- Assembly
- Ranorex.Plugin.Web.dll
The element represents a web element (tag) inside of a web document DOM.
public class WebElement : Adapter, IAdapter
- Inheritance
-
WebElement
- Implements
- Derived
- Inherited Members
Constructors
WebElement()
Creates a new WebElement adapter instance. This constructor is used internally by the Ranorex Core Framework for performance issues!
protected WebElement()
WebElement(Element)
Creates a new WebElement adapter instance.
public WebElement(Element element)
Parameters
elementElementThe element to create the adapter for.
Exceptions
- NullReferenceException
If
elementisnull.- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.
Properties
Class
The CSS class names of the element.
public virtual string Class { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
ContentEditable
Specifies if the user is allowed to edit the content or not.
public virtual string ContentEditable { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
ContextMenu
Specifies the context menu for an element.
public virtual string ContextMenu { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
Draggable
Specifies whether or not a user is allowed to drag an element.
public virtual string Draggable { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
Hidden
Specifies that the element is not relevant. Hidden elements are not displayed.
public virtual string Hidden { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
Id
A unique id for the element.
public virtual string Id { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
InnerText
The inner text (without markup) of the web element.
public virtual string InnerText { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
this[string]
Gets the attribute with the specified name.
public string this[string attributeName] { get; set; }
Parameters
attributeNamestring
Property Value
- string
The attribute value or null if nothing was found for that name.
NextSibling
Gets the next web element sibling or null if this element is the last of its parent's children.
public WebElement NextSibling { get; }
Property Value
- WebElement
The next sibling.
OwnerDocument
Gets the owner document of the web element or null if not found.
public WebDocument OwnerDocument { get; }
Property Value
Parent
Gets the parent web element or null if the root of the web document has been reached.
public WebElement Parent { get; }
Property Value
- WebElement
The parent web element.
PreviousSibling
Gets the previous web element sibling or null if this element is the first of its parent's children.
public WebElement PreviousSibling { get; }
Property Value
- WebElement
The previous sibling.
RequiredCapabilities
Capabilities required by the adapter implementation.
protected override string[] RequiredCapabilities { get; }
Property Value
- string[]
SafeClass
The filtered and normalized CSS class names of the element.
public virtual string SafeClass { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
TagName
The name of the HTML tag the webelement represents.
public virtual string TagName { get; }
Property Value
TagValue
The contents of the tag value attribute.
public virtual string TagValue { get; set; }
Property Value
Exceptions
- SetAttributeFailedException
Thrown if setting the attribute value failed.
Methods
FromElement(Element)
Converts an Element to an instance of this class.
public static WebElement FromElement(Element element)
Parameters
elementElementThe element to convert.
Returns
- WebElement
The WebElement.
Exceptions
- ArgumentNullException
If
elementisnull.- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.
FromPath(string)
Converts a string to an instance of this class by searching the root.
public static WebElement FromPath(string path)
Parameters
pathstringThe search path.
Returns
- WebElement
The WebElement.
Remarks
The DefaultSearchTimeout is used to search for the specified path.
Exceptions
- ArgumentNullException
If
pathisnull.- RxPathException
If the specified
pathis not valid.- ElementNotFoundException
If no element is found.
- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.
GetInnerHtml()
Retrieves the inner HTML (including markup) of the web element.
public virtual string GetInnerHtml()
Returns
- string
The inner HTML.
Exceptions
- ActionFailedException
Thrown if invoking the action failed.
GetOrCreateId()
Returns a unique 'id' attribute for this WebElement. If an id is set, the original value is returned, otherwise the WebElement is assigned a new random id. Use this method to pass elements by id to Javascript code.
public string GetOrCreateId()
Returns
- string
The unique 'id' of this WebElement.
GetStyle(string)
Retrieves a CSS style attribute from an element (by name).
public virtual string GetStyle(string name)
Parameters
namestringThe name of the style.
Returns
- string
The value of the CSS style attribute.
Exceptions
- ActionFailedException
Thrown if invoking the action failed.
PerformClick()
Performs a click on the web element without using the mouse.
public virtual void PerformClick()
Exceptions
- ActionFailedException
Thrown if invoking the action failed.
RaiseEvent(string)
Raises an event on the web element (by name).
public virtual void RaiseEvent(string name)
Parameters
namestringThe name of the event.
Exceptions
- ActionFailedException
Thrown if invoking the action failed.
SetStyle(string, string)
Sets a CSS style attribute of an element (by name).
public virtual void SetStyle(string name, string value)
Parameters
Exceptions
- ActionFailedException
Thrown if invoking the action failed.
Operators
implicit operator WebElement(Element)
Implicitly converts an Element to an instance of this class.
public static implicit operator WebElement(Element element)
Parameters
elementElementThe element to convert.
Returns
- WebElement
The WebElement.
Exceptions
- ArgumentNullException
If
elementisnull.- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.
implicit operator WebElement(string)
Implicitly converts a string to an instance of this class by searching the root.
public static implicit operator WebElement(string path)
Parameters
pathstringThe search path.
Returns
- WebElement
The WebElement.
Remarks
The DefaultSearchTimeout is used to search for the specified path.
Exceptions
- ArgumentNullException
If
pathisnull.- RxPathException
If the specified
pathis not valid.- ElementNotFoundException
If no element is found.
- CapabilityNotSupportedException
If the element does not support the capabilities required by this adapter.