Provides a mechanism by which to find elements within a document.
[Serializable]
public class By
By
Initializes a new instance of the By class.
By(Func<ISearchContext, IWebElement>, Func<ISearchContext, ReadOnlyCollection<IWebElement>>)Initializes a new instance of the By class using the given functions to find elements.
protected By(Func<ISearchContext, IWebElement> findElementMethod, Func<ISearchContext, ReadOnlyCollection<IWebElement>> findElementsMethod)
Parameters
findElementMethod
Func<ISearchContext, IWebElement>
A function that takes an object implementing ISearchContext and returns the found IWebElement.
findElementsMethod
Func<ISearchContext, ReadOnlyCollection<IWebElement>>
A function that takes an object implementing ISearchContext and returns a ReadOnlyCollection<T> of the foundIWebElements. IWebElements/>.
Initializes a new instance of the By class using the specified mechanism and criteria for finding elements.
protected By(string mechanism, string criteria)
Parameters
mechanism
string
The mechanism to use in finding elements.
criteria
string
The criteria to use in finding elements.
Gets the value of the criteria for this By class instance.
public string Criteria { get; }
Property Value
Gets or sets the value of the description for this By class instance.
protected string Description { get; set; }
Property Value
Gets or sets the method used to find a single element matching specified criteria, or throws NoSuchElementException if no element is found.
protected Func<ISearchContext, IWebElement>? FindElementMethod { get; set; }
Property Value
Gets or sets the method used to find all elements matching specified criteria.
protected Func<ISearchContext, ReadOnlyCollection<IWebElement>>? FindElementsMethod { get; set; }
Property Value
Gets the value of the mechanism for this By class instance.
public string Mechanism { get; }
Property Value
Gets a mechanism to find elements by their CSS class.
public static By ClassName(string classNameToFind)
Parameters
classNameToFind
string
The CSS class to find.
A By object the driver can use to find the elements.
If classNameToFind
is null.
Gets a mechanism to find elements by their cascading style sheet (CSS) selector.
public static By CssSelector(string cssSelectorToFind)
Parameters
cssSelectorToFind
string
The CSS selector to find.
A By object the driver can use to find the elements.
If cssSelectorToFind
is null.
Determines whether the specified Object is equal to the current Object.
public override bool Equals(object? obj)
Parameters
Returns
FindElement(ISearchContext)
Finds the first element matching the criteria.
public virtual IWebElement FindElement(ISearchContext context)
Parameters
context
ISearchContext
An ISearchContext object to use to search for the elements.
The first matching IWebElement on the current context.
If no element matches the criteria.
Finds all elements matching the criteria.
public virtual ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
Parameters
context
ISearchContext
An ISearchContext object to use to search for the elements.
A ReadOnlyCollection<T> of all WebElements matching the current criteria, or an empty list if nothing matches.
Serves as a hash function for a particular type.
public override int GetHashCode()
Returns
A hash code for the current Object.
Gets a mechanism to find elements by their ID.
public static By Id(string idToFind)
Parameters
idToFind
string
The ID to find.
A By object the driver can use to find the elements.
If idToFind
is null.
Gets a mechanism to find elements by their link text.
public static By LinkText(string linkTextToFind)
Parameters
linkTextToFind
string
The link text to find.
A By object the driver can use to find the elements.
If linkTextToFind
is null.
Gets a mechanism to find elements by their name.
public static By Name(string nameToFind)
Parameters
nameToFind
string
The name to find.
A By object the driver can use to find the elements.
If nameToFind
is null.
Gets a mechanism to find elements by a partial match on their link text.
public static By PartialLinkText(string partialLinkTextToFind)
Parameters
partialLinkTextToFind
string
The partial link text to find.
A By object the driver can use to find the elements.
If partialLinkTextToFind
is null.
Gets a mechanism to find elements by their tag name.
public static By TagName(string tagNameToFind)
Parameters
tagNameToFind
string
The tag name to find.
A By object the driver can use to find the elements.
If tagNameToFind
is null.
Gets a string representation of the finder.
public override string ToString()
Returns
The string displaying the finder content.
Gets a mechanism to find elements by an XPath query. When searching within a WebElement using xpath be aware that WebDriver follows standard conventions: a search prefixed with "//" will search the entire document, not just the children of this current node. Use ".//" to limit your search to the children of this WebElement.
public static By XPath(string xpathToFind)
Parameters
xpathToFind
string
The XPath query to use.
A By object the driver can use to find the elements.
If xpathToFind
is null.
Determines if two By instances are equal.
public static bool operator ==(By? one, By? two)
Parameters
one
By
One instance to compare.
two
By
The other instance to compare.
Determines if two By instances are unequal.
public static bool operator !=(By? one, By? two)
Parameters
one
By
One instance to compare.
two
By
The other instance to compare.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4