FindsByAttribute ClassWebDriver
Marks program elements with methods by which to find a corresponding element on the page. Used in conjunction with the PageFactory, it allows you to quickly create Page Objects.
Inheritance Hierarchy


Namespace: OpenQA.Selenium.Support.PageObjects
Assembly: WebDriver.Support (in WebDriver.Support.dll) Version: 3.1.0

public sealed class FindsByAttribute : Attribute, 

The FindsByAttribute type exposes the following members.


Public methodFindsByAttribute
Initializes a new instance of the FindsByAttribute class

Public propertyCustomFinderType
Gets or sets a value indicating the Type of the custom finder. The custom finder must descend from the By class, and expose a public constructor that takes a String argument.
Public propertyHow
Gets or sets the method used to look up the element
Public propertyPriority
Gets or sets a value indicating where this attribute should be evaluated relative to other instances of this attribute decorating the same class member.
Public propertyTypeId
When implemented in a derived class, gets a unique identifier for this Attribute.
(Inherited from Attribute.)
Public propertyUsing
Gets or sets the value to lookup by (i.e. for How.Name, the actual name to look up)

Public methodCompareTo
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Overrides AttributeEquals(Object).)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Overrides AttributeGetHashCode.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIsDefaultAttribute
When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.
(Inherited from Attribute.)
Public methodMatch
When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.
(Inherited from Attribute.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)

Public operatorStatic memberEquality
Determines if two FindsByAttribute instances are equal.
Public operatorStatic memberGreaterThan
Determines if one FindsByAttribute instance is greater than another.
Public operatorStatic memberInequality
Determines if two FindsByAttribute instances are unequal.
Public operatorStatic memberLessThan
Determines if one FindsByAttribute instance is less than another.

You can use this attribute by specifying the How and Using properties to indicate how to find the elements. This attribute can be used to decorate fields and properties in your Page Object classes. The Type of the field or property must be either IWebElement or IList{IWebElement}. Any other type will throw an ArgumentException when InitElements(ISearchContext, Object) is called.

[FindsBy(How = How.Name, Using = "myElementName")]
public IWebElement foundElement;

[FindsBy(How = How.TagName, Using = "a")]
public IList{IWebElement} allLinks;

You can also use multiple instances of this attribute to find an element that may meet one of multiple criteria. When using multiple instances, you can specify the order in which the criteria is matched by using the Priority property.

// Will find the element with the name attribute matching the first of "anElementName"
// or "differentElementName".
[FindsBy(How = How.Name, Using = "anElementName", Priority = 0)]
[FindsBy(How = How.Name, Using = "differentElementName", Priority = 1)]
public IWebElement thisElement;

See Also