下面列出了org.openqa.selenium.By#findElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected boolean clickSelectOption(WebElement element, String optionValue) {
boolean result = false;
if (element != null) {
if (isSelect(element)) {
optionValue = cleanupValue(optionValue);
By optionBy = new OptionBy(optionValue);
WebElement option = optionBy.findElement(element);
result = clickSelectOption(element, option);
}
}
return result;
}
/**
* Converts By to Function returning first result (or null).
* @param by by to convert.
* @return function returning first result of by.
*/
public static <T extends WebElement> Function<SearchContext, T> byToFunction(By by) {
Function<SearchContext, T> function;
if (by instanceof SingleElementOrNullBy) {
// will not throw exception, but return null when no element is found
function = sc -> (T) by.findElement(sc);
} else {
function = sc -> {
// single element case will throw exception when no element is found
List elements = by.findElements(sc);
return (elements != null && !elements.isEmpty())? (T) elements.get(0) : null;
};
}
return function;
}
public static <T extends WebElement> T getWebElement(By by, SearchContext context) {
T byResult;
if (by instanceof SingleElementOrNullBy) {
byResult = (T) by.findElement(context);
} else {
byResult = BestMatchBy.findElement(by, context);
}
return byResult;
}
@Override
public WebElement findElement(By locator) {
if (locator instanceof By.StandardLocator) {
return ((By.StandardLocator) locator).findElement(this, this::findElement);
} else {
return locator.findElement(this);
}
}
@Override
public WebElement findElement(By by) {
if (by instanceof By.StandardLocator) {
return ((By.StandardLocator) by).findElement(this, this::findElement);
} else {
return by.findElement(this);
}
}