public abstract class By extends 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(String className)
Finds elements based on the value of the "class" attribute.
|
static By |
cssSelector(String selector)
Finds elements via the driver's underlying W3 Selector engine.
|
boolean |
equals(Object o) |
WebElement |
findElement(SearchContext context)
Find a single element.
|
abstract List<WebElement> |
findElements(SearchContext context)
Find many elements.
|
int |
hashCode() |
static By |
id(String id) |
static By |
linkText(String linkText) |
static By |
name(String name) |
static By |
partialLinkText(String linkText) |
static By |
tagName(String name) |
String |
toString() |
static By |
xpath(String xpathExpression) |
public static By id(String id)
id
- The value of the "id" attribute to search forpublic static By linkText(String linkText)
linkText
- The exact text to match againstpublic static By partialLinkText(String linkText)
linkText
- The text to match againstpublic static By name(String name)
name
- The value of the "name" attribute to search forpublic static By tagName(String name)
name
- The element's tagNamepublic static By xpath(String xpathExpression)
xpathExpression
- The xpath to usepublic static By className(String className)
className
- The value of the "class" attribute to search forpublic static By cssSelector(String selector)
public WebElement findElement(SearchContext context)
context
- A context to use to find the elementpublic abstract List<WebElement> findElements(SearchContext context)
context
- A context to use to find the elementCopyright © 2013. All Rights Reserved.