use of com.axway.ats.uiengine.HiddenBrowserDriver in project ats-framework by Axway.
the class HiddenHtmlElementLocator method findElement.
public static HtmlUnitWebElement findElement(UiElement uiElement, String xpathSuffix, boolean verbose) {
HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiElement.getUiDriver();
WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);
String xpath = uiElement.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
String css = uiElement.getElementProperty("_css");
if (xpathSuffix != null) {
xpath += xpathSuffix;
}
List<WebElement> elements = null;
if (!StringUtils.isNullOrEmpty(css)) {
elements = webDriver.findElements(By.cssSelector(css));
} else {
elements = webDriver.findElements(By.xpath(xpath));
}
if (elements.size() == 0) {
throw new ElementNotFoundException(uiElement.toString() + " not found.");
} else if (elements.size() > 1) {
if (verbose) {
log.warn("More than one HTML elements were found having properties " + uiElement.toString() + ".Only the first HTML element will be used.");
}
}
HtmlUnitWebElement element = (HtmlUnitWebElement) elements.get(0);
if (verbose) {
log.info("Found element: " + element.toString());
}
return element;
}
Aggregations