Table of Contents

Class RemoteWebElement

Namespace
OpenQA.Selenium.Remote
Assembly
WebDriver.dll

RemoteWebElement allows you to have access to specific items that are found on the page

public class RemoteWebElement : IWebElement, ISearchContext, IFindsByLinkText, IFindsById, IFindsByName, IFindsByTagName, IFindsByClassName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, IWrapsDriver, ILocatable, ITakesScreenshot
Inheritance
RemoteWebElement
Implements
Derived
Inherited Members

Constructors

RemoteWebElement(RemoteWebDriver, string)

Initializes a new instance of the RemoteWebElement class.

public RemoteWebElement(RemoteWebDriver parentDriver, string id)

Parameters

parentDriver RemoteWebDriver

The RemoteWebDriver instance hosting this element.

id string

The ID assigned to the element.

Properties

Coordinates

Gets the coordinates identifying the location of this element using various frames of reference.

public ICoordinates Coordinates { get; }

Property Value

ICoordinates

Displayed

Gets a value indicating whether or not this element is displayed.

public bool Displayed { get; }

Property Value

bool

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.

public bool Enabled { get; }

Property Value

bool

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.

Id

Gets the ID of the element

protected string Id { get; }

Property Value

string

Remarks

This property is internal to the WebDriver instance, and is not intended to be used in your code. The element's ID has no meaning outside of internal WebDriver usage, so it would be improper to scope it as public. However, both subclasses of RemoteWebElement and the parent driver hosting the element have a need to access the internal element ID. Therefore, we have two properties returning the same value, one scoped as internal, the other as protected.

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.

public Point Location { get; }

Property Value

Point

Exceptions

StaleElementReferenceException

Thrown when the target element is no longer valid in the document DOM.

LocationOnScreenOnceScrolledIntoView

Gets the point where the element would be when scrolled into view.

public Point LocationOnScreenOnceScrolledIntoView { get; }

Property Value

Point

Selected

Gets a value indicating whether or not this element is selected.

public bool Selected { get; }

Property Value

bool

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.

public Size Size { get; }

Property Value

Size

Exceptions

StaleElementReferenceException

Thrown when the target element is no longer valid in the document DOM.

TagName

Gets the tag name of this element.

public string TagName { get; }

Property Value

string

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

Gets the innerText of this element, without any leading or trailing whitespace, and with other whitespace collapsed.

public string Text { get; }

Property Value

string

Exceptions

StaleElementReferenceException

Thrown when the target element is no longer valid in the document DOM.

WrappedDriver

Gets the IWebDriver used to find this element.

public IWebDriver WrappedDriver { get; }

Property Value

IWebDriver

Methods

Clear()

Clears the content of this element.

public 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.

public 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.

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.

Equals(object)

Compares if two elements are equal

public override bool Equals(object obj)

Parameters

obj object

Object to compare against

Returns

bool

A boolean if it is equal or not

Execute(string, Dictionary<string, object>)

Executes a command on this element using the specified parameters.

protected Response Execute(string commandToExecute, Dictionary<string, object> parameters)

Parameters

commandToExecute string

The DriverCommand to execute against this element.

parameters Dictionary<string, object>

A Dictionary<TKey, TValue> containing names and values of the parameters for the command.

Returns

Response

The Response object containing the result of the command execution.

FindElement(By)

Finds the first IWebElement using the given method.

public IWebElement FindElement(By by)

Parameters

by By

The locating mechanism to use.

Returns

IWebElement

The first matching IWebElement on the current context.

Exceptions

NoSuchElementException

If no element matches the criteria.

FindElement(string, string)

Finds a child element matching the given mechanism and value.

protected IWebElement FindElement(string mechanism, string value)

Parameters

mechanism string

The mechanism by which to find the element.

value string

The value to use to search for the element.

Returns

IWebElement

The first IWebElement matching the given criteria.

FindElementByClassName(string)

Finds the first element in the page that matches the CSS Class supplied

public IWebElement FindElementByClassName(string className)

Parameters

className string

CSS class name of the element on the page

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementByClassName("classname")

FindElementByCssSelector(string)

Finds the first element matching the specified CSS selector.

public IWebElement FindElementByCssSelector(string cssSelector)

Parameters

cssSelector string

The id to match.

Returns

IWebElement

The first IWebElement matching the criteria.

FindElementById(string)

Finds the first element in the page that matches the ID supplied

public IWebElement FindElementById(string id)

Parameters

id string

ID of the element

Returns

IWebElement

IWebElement object so that you can interact with that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementById("id")

FindElementByLinkText(string)

Finds the first of elements that match the link text supplied

public IWebElement FindElementByLinkText(string linkText)

Parameters

linkText string

Link text of element

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementByLinkText("linktext")

FindElementByName(string)

Finds the first of elements that match the name supplied

public IWebElement FindElementByName(string name)

Parameters

name string

Name of the element

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
elem = driver.FindElementsByName("name")

FindElementByPartialLinkText(string)

Finds the first of elements that match the part of the link text supplied

public IWebElement FindElementByPartialLinkText(string partialLinkText)

Parameters

partialLinkText string

part of the link text

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByPartialLinkText("partOfLink")

FindElementByTagName(string)

Finds the first of elements that match the DOM Tag supplied

public IWebElement FindElementByTagName(string tagName)

Parameters

tagName string

tag name of the element

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByTagName("tag")

FindElementByXPath(string)

Finds the first of elements that match the XPath supplied

public IWebElement FindElementByXPath(string xpath)

Parameters

xpath string

xpath to the element

Returns

IWebElement

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
IWebElement elem = driver.FindElementsByXPath("//table/tbody/tr/td/a");

FindElements(By)

Finds all IWebElements within the current context using the given mechanism.

public ReadOnlyCollection<IWebElement> FindElements(By by)

Parameters

by By

The locating mechanism to use.

Returns

ReadOnlyCollection<IWebElement>

A ReadOnlyCollection<T> of all WebElements matching the current criteria, or an empty list if nothing matches.

FindElements(string, string)

Finds all child elements matching the given mechanism and value.

protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value)

Parameters

mechanism string

The mechanism by which to find the elements.

value string

The value to use to search for the elements.

Returns

ReadOnlyCollection<IWebElement>

A collection of all of the IWebElements matching the given criteria.

FindElementsByClassName(string)

Finds a list of elements that match the class name supplied

public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)

Parameters

className string

CSS class name of the elements on the page

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of IWebElement object so that you can interact with those objects

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByClassName("classname")

FindElementsByCssSelector(string)

Finds all elements matching the specified CSS selector.

public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector)

Parameters

cssSelector string

The CSS selector to match.

Returns

ReadOnlyCollection<IWebElement>

A ReadOnlyCollection<T> containing all IWebElements matching the criteria.

FindElementsById(string)

Finds the first element in the page that matches the ID supplied

public ReadOnlyCollection<IWebElement> FindElementsById(string id)

Parameters

id string

ID of the Element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of Elements that match the object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsById("id")

FindElementsByLinkText(string)

Finds the first of elements that match the link text supplied

public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)

Parameters

linkText string

Link text of element

Returns

ReadOnlyCollection<IWebElement>

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByLinkText("linktext")

FindElementsByName(string)

Finds a list of elements that match the name supplied

public ReadOnlyCollection<IWebElement> FindElementsByName(string name)

Parameters

name string

Name of element

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollect of IWebElement objects so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByName("name")

FindElementsByPartialLinkText(string)

Finds a list of elements that match the link text supplied

public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText)

Parameters

partialLinkText string

part of the link text

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection<IWebElement> objects so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByPartialLinkText("partOfTheLink")

FindElementsByTagName(string)

Finds a list of elements that match the DOM Tag supplied

public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)

Parameters

tagName string

DOM Tag of the element on the page

Returns

ReadOnlyCollection<IWebElement>

IWebElement object so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByTagName("tag")

FindElementsByXPath(string)

Finds a list of elements that match the XPath supplied

public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)

Parameters

xpath string

xpath to element on the page

Returns

ReadOnlyCollection<IWebElement>

ReadOnlyCollection of IWebElement objects so that you can interact that object

Examples

IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.Firefox());
ReadOnlyCollection<IWebElement> elem = driver.FindElementsByXpath("//tr/td/a")

GetAttribute(string)

Gets the value of the specified attribute for this element.

public string GetAttribute(string attributeName)

Parameters

attributeName string

The name of the attribute.

Returns

string

The attribute's current value. Returns a null if the value is not set.

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 nameValue returned if not explicitly specifiedValid element types
checkedcheckedCheck Box
selectedselectedOptions in Select elements
disableddisabledInput 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.

public string GetCssValue(string propertyName)

Parameters

propertyName string

The 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.

GetHashCode()

Method to get the hash code of the element

public override int GetHashCode()

Returns

int

Integer of the hash code for the element

GetScreenshot()

Gets a Screenshot object representing the image of this element on the screen.

public Screenshot GetScreenshot()

Returns

Screenshot

A Screenshot object containing the image.

SendKeys(string)

Simulates typing text into the element.

public void SendKeys(string text)

Parameters

text string

The 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.

public 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 attempt to block until the new page is loaded.

Exceptions

StaleElementReferenceException

Thrown when the target element is no longer valid in the document DOM.

See Also