Interface IWebElement
Defines the interface through which the user controls elements on the page.
public interface IWebElement : ISearchContext
- Inherited Members
Remarks
The IWebElement interface represents an HTML element. Generally, all interesting operations to do with interacting with a page will be performed through this interface.
Properties
Displayed
Gets a value indicating whether or not this element is displayed.
bool Displayed { get; }
Property Value
Remarks
The Displayed property avoids the problem of having to parse an element's "style" attribute to determine visibility of an element.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Enabled
Gets a value indicating whether or not this element is enabled.
bool Enabled { get; }
Property Value
Remarks
The Enabled property will generally return true for everything except explicitly disabled input elements.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Location
Gets a Point object containing the coordinates of the upper-left corner of this element relative to the upper-left corner of the page.
Point Location { get; }
Property Value
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Selected
Gets a value indicating whether or not this element is selected.
bool Selected { get; }
Property Value
Remarks
This operation only applies to input elements such as checkboxes, options in a select element and radio buttons.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Size
Gets a Size object containing the height and width of this element.
Size Size { get; }
Property Value
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
TagName
Gets the tag name of this element.
string TagName { get; }
Property Value
Remarks
The TagName property returns the tag name of the element, not the value of the name attribute. For example, it will return "input" for an element specified by the HTML markup <input name="foo" />.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Text
Get the visible (i.e. not hidden by CSS) text of this element, including sub-elements.
string Text { get; }
Property Value
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Methods
Clear()
Clears the content of this element.
void Clear()
Remarks
If this element is a text entry element, the Clear() method will clear the value. It has no effect on other elements. Text entry elements are defined as elements with INPUT or TEXTAREA tags.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
Click()
Clicks this element.
void Click()
Remarks
Click this element. If the click causes a new page to load, the Click() method will attempt to block until the page has loaded. After calling the Click() method, you should discard all references to this element unless you know that the element and the page will still be present. Otherwise, any further operations performed on this element will have an undefined. behavior.
If this element is not clickable, then this operation is ignored. This allows you to simulate a users to accidentally missing the target when clicking.
Exceptions
- ElementNotVisibleException
Thrown when the target element is not visible.
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
GetAttribute(string)
Gets the value of the specified attribute for this element.
string GetAttribute(string attributeName)
Parameters
attributeName
stringThe name of the attribute.
Returns
Remarks
The GetAttribute(string) method will return the current value of the attribute, even if the value has been modified after the page has been loaded. Note that the value of the following attributes will be returned even if there is no explicit attribute on the element:
Attribute name | Value returned if not explicitly specified | Valid element types |
---|---|---|
checked | checked | Check Box |
selected | selected | Options in Select elements |
disabled | disabled | Input and other UI elements |
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
GetCssValue(string)
Gets the value of a CSS property of this element.
string GetCssValue(string propertyName)
Parameters
propertyName
stringThe name of the CSS property to get the value of.
Returns
- string
The value of the specified CSS property.
Remarks
The value returned by the GetCssValue(string) method is likely to be unpredictable in a cross-browser environment. Color values should be returned as hex strings. For example, a "background-color" property set as "green" in the HTML source, will return "#008000" for its value.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
GetDomAttribute(string)
Gets the value of a declared HTML attribute of this element.
string GetDomAttribute(string attributeName)
Parameters
attributeName
stringThe name of the HTML attribute to get the value of.
Returns
- string
The HTML attribute's current value. Returns a null if the value is not set or the declared attribute does not exist.
Remarks
As opposed to the GetAttribute(string) method, this method only returns attributes declared in the element's HTML markup. To access the value of an IDL property of the element, either use the GetAttribute(string) method or the GetDomProperty(string) method.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
GetDomProperty(string)
Gets the value of a JavaScript property of this element.
string GetDomProperty(string propertyName)
Parameters
propertyName
stringThe name of the JavaScript property to get the value of.
Returns
- string
The JavaScript property's current value. Returns a null if the value is not set or the property does not exist.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
GetShadowRoot()
Gets the representation of an element's shadow root for accessing the shadow DOM of a web component.
ISearchContext GetShadowRoot()
Returns
- ISearchContext
A shadow root representation.
Exceptions
- NoSuchShadowRootException
Thrown when this element does not have a shadow root.
SendKeys(string)
Simulates typing text into the element.
void SendKeys(string text)
Parameters
text
stringThe text to type into the element.
Remarks
The text to be typed may include special characters like arrow keys, backspaces, function keys, and so on. Valid special keys are defined in Keys.
Exceptions
- InvalidElementStateException
Thrown when the target element is not enabled.
- ElementNotVisibleException
Thrown when the target element is not visible.
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.
- See Also
Submit()
Submits this element to the web server.
void Submit()
Remarks
If this current element is a form, or an element within a form, then this will be submitted to the web server. If this causes the current page to change, then this method will block until the new page is loaded.
Exceptions
- StaleElementReferenceException
Thrown when the target element is no longer valid in the document DOM.