Search in sources :

Example 1 with HiddenBrowserDriver

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;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) HiddenBrowserDriver(com.axway.ats.uiengine.HiddenBrowserDriver) HtmlUnitWebElement(org.openqa.selenium.htmlunit.HtmlUnitWebElement) ElementNotFoundException(com.axway.ats.uiengine.exceptions.ElementNotFoundException) WebElement(org.openqa.selenium.WebElement) HtmlUnitWebElement(org.openqa.selenium.htmlunit.HtmlUnitWebElement)

Aggregations

HiddenBrowserDriver (com.axway.ats.uiengine.HiddenBrowserDriver)1 ElementNotFoundException (com.axway.ats.uiengine.exceptions.ElementNotFoundException)1 WebDriver (org.openqa.selenium.WebDriver)1 WebElement (org.openqa.selenium.WebElement)1 HtmlUnitWebElement (org.openqa.selenium.htmlunit.HtmlUnitWebElement)1