public abstract class By
extends java.lang.Object
public WebElement findElement(WebDriver driver) {
WebElement element = driver.findElement(By.id(getSelector()));
if (element == null)
element = driver.findElement(By.name(getSelector());
return element;
}
Modifier and Type | Class and Description |
---|---|
static class |
By.ByClassName |
static class |
By.ByCssSelector |
static class |
By.ById |
static class |
By.ByLinkText |
static class |
By.ByName |
static class |
By.ByPartialLinkText |
static class |
By.ByTagName |
static class |
By.ByXPath |
Constructor and Description |
---|
By() |
Modifier and Type | Method and Description |
---|---|
static By |
className(java.lang.String className)
Finds elements based on the value of the "class" attribute.
|
static By |
cssSelector(java.lang.String selector)
Finds elements via the driver's underlying W3 Selector engine.
|
boolean |
equals(java.lang.Object o) |
WebElement |
findElement(SearchContext context)
Find a single element.
|
abstract java.util.List<WebElement> |
findElements(SearchContext context)
Find many elements.
|
int |
hashCode() |
static By |
id(java.lang.String id) |
static By |
linkText(java.lang.String linkText) |
static By |
name(java.lang.String name) |
static By |
partialLinkText(java.lang.String linkText) |
static By |
tagName(java.lang.String name) |
java.lang.String |
toString() |
static By |
xpath(java.lang.String xpathExpression) |
public static By id(java.lang.String id)
id
- The value of the "id" attribute to search forpublic static By linkText(java.lang.String linkText)
linkText
- The exact text to match againstpublic static By partialLinkText(java.lang.String linkText)
linkText
- The text to match againstpublic static By name(java.lang.String name)
name
- The value of the "name" attribute to search forpublic static By tagName(java.lang.String name)
name
- The element's tagNamepublic static By xpath(java.lang.String xpathExpression)
xpathExpression
- The xpath to usepublic static By className(java.lang.String className)
className
- The value of the "class" attribute to search forpublic static By cssSelector(java.lang.String selector)
selector
- css expressionpublic WebElement findElement(SearchContext context)
context
- A context to use to find the elementpublic abstract java.util.List<WebElement> findElements(SearchContext context)
context
- A context to use to find the elementpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object