Search in sources :

Example 1 with InvalidElementStateException

use of org.openqa.selenium.InvalidElementStateException in project ats-framework by Axway.

the class HtmlFileBrowse method setFileInputValue.

/**
    *
    * @param webDriver {@link WebDriver} instance
    * @param value the file input value to set
    */
protected void setFileInputValue(WebDriver webDriver, String value) {
    String locator = this.getElementProperties().getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);
    String css = this.getElementProperty("_css");
    WebElement element = null;
    if (!StringUtils.isNullOrEmpty(css)) {
        element = webDriver.findElement(By.cssSelector(css));
    } else {
        element = webDriver.findElement(By.xpath(locator));
    }
    try {
        element.sendKeys(value);
    } catch (ElementNotVisibleException enve) {
        if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) {
            throw enve;
        }
        // try to make the element visible overriding some CSS properties
        // but keep in mind that it can be still invisible using another CSS and/or JavaScript techniques
        String styleAttrValue = element.getAttribute("style");
        JavascriptExecutor jsExec = (JavascriptExecutor) webDriver;
        try {
            jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "display:'block'; visibility:'visible'; top:'auto'; left:'auto'; z-index:999;" + "height:'auto'; width:'auto';");
            element.sendKeys(value);
        } finally {
            jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, styleAttrValue);
        }
    } catch (InvalidElementStateException e) {
        throw new SeleniumOperationException(e.getMessage(), e);
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) WebElement(org.openqa.selenium.WebElement) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) InvalidElementStateException(org.openqa.selenium.InvalidElementStateException) ElementNotVisibleException(org.openqa.selenium.ElementNotVisibleException)

Aggregations

SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)1 ElementNotVisibleException (org.openqa.selenium.ElementNotVisibleException)1 InvalidElementStateException (org.openqa.selenium.InvalidElementStateException)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 WebElement (org.openqa.selenium.WebElement)1