Search in sources :

Example 1 with ElementNotVisibleException

use of org.openqa.selenium.ElementNotVisibleException 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)

Example 2 with ElementNotVisibleException

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

the class RealHtmlButton method doClick.

private void doClick() {
    try {
        new RealHtmlElementState(this).waitToBecomeExisting();
        WebElement element = RealHtmlElementLocator.findElement(this);
        try {
            element.click();
        } catch (ElementNotVisibleException enve) {
            if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) {
                throw enve;
            }
            ((JavascriptExecutor) webDriver).executeScript("arguments[0].click()", element);
        }
    } catch (Exception e) {
        ((AbstractRealBrowserDriver) super.getUiDriver()).clearExpectedPopups();
        throw new SeleniumOperationException(this, "click", e);
    }
    UiEngineUtilities.sleep();
    ((AbstractRealBrowserDriver) super.getUiDriver()).handleExpectedPopups();
}
Also used : RealHtmlElementState(com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) WebElement(org.openqa.selenium.WebElement) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotVisibleException(org.openqa.selenium.ElementNotVisibleException) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) ElementNotVisibleException(org.openqa.selenium.ElementNotVisibleException)

Aggregations

SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)2 ElementNotVisibleException (org.openqa.selenium.ElementNotVisibleException)2 WebElement (org.openqa.selenium.WebElement)2 AbstractRealBrowserDriver (com.axway.ats.uiengine.AbstractRealBrowserDriver)1 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)1 InvalidElementStateException (org.openqa.selenium.InvalidElementStateException)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1