Example usage for org.openqa.selenium WebElement isEnabled

List of usage examples for org.openqa.selenium WebElement isEnabled

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement isEnabled.

Prototype

boolean isEnabled();

Source Link

Document

Is the element currently enabled or not?

Usage

From source file:org.specrunner.webdriver.assertions.AbstractPluginEnabled.java

License:Open Source License

@Override
protected void process(IContext context, IResultSet result, WebDriver client, WebElement[] elements)
        throws PluginException {
    boolean error = false;
    for (WebElement element : elements) {
        if (enabled() != element.isEnabled()) {
            result.addResult(Failure.INSTANCE, context.peek(),
                    new PluginException("Element " + getFinderInstance().resume(context) + " should be '"
                            + (enabled() ? "enabled" : "disabled") + "' but is '"
                            + (element.isEnabled() ? "enabled" : "disabled") + "'."),
                    SRServices.get(IWritableFactoryManager.class).get(WebDriver.class).newWritable(client));
            error = true;// ww w .  java2 s .  co m
        }
    }
    if (!error) {
        result.addResult(Success.INSTANCE, context.peek());
    }
}

From source file:org.testeditor.fixture.web.AbstractWebFixture.java

License:Open Source License

/**
 * Checks if a web element is active (Enabled).
 * /*from   w ww . ja  v  a 2 s  .  co m*/
 * Therefore it is ensured that the element is available (present in DOM and
 * visible on web page). If element is not available a
 * {@code StopTestException} is thrown.
 * 
 * @param elementListKey
 *            key in the element list to find the technical locator
 * @param replaceArgs
 *            values to replace the place holders in the element list entry
 * @return {@code true} if the web element is active (enabled),
 *         {@code false} otherwise
 * @throws StopTestException
 *             if element not available (hidden, not present) or a timeout
 *             occurred
 */
public boolean checkElementIsActive(String elementListKey, String... replaceArgs) throws StopTestException {
    WebElement element = findAvailableWebElement(elementListKey, replaceArgs);
    return element.isEnabled();
}

From source file:org.testeditor.fixture.web.AbstractWebFixture.java

License:Open Source License

/**
 * Checks if a web element is inactive (disabled).
 * /*www  .  j a v a 2  s.c o  m*/
 * Therefore it is ensured that the element is available (present in DOM and
 * visible on web page). If element is not available a
 * {@code StopTestException} is thrown.
 * 
 * @param elementListKey
 *            key in the element list to find the technical locator
 * @param replaceArgs
 *            values to replace the place holders in the element list entry
 * @return {@code true} if the web element is inactive (disabled),
 *         {@code false} otherwise
 * @throws StopTestException
 *             if element not available (hidden, not present) or a timeout
 *             occurred
 */
public boolean checkElementIsInactive(String elementListKey, String... replaceArgs) throws StopTestException {
    WebElement element = findAvailableWebElement(elementListKey, replaceArgs);
    return !element.isEnabled();
}

From source file:org.testeditor.fixture.web.WebDriverFixture.java

License:Open Source License

/**
 * /* ww  w .ja  v a 2s. c  om*/
 * @param elementLocator Locator for Gui-Widget
 * @param locatorType Type of locator for Gui-Widget
 * @return true if a checkable Gui-Widget is checked, false otherwise.
 */
@FixtureMethod
public Boolean checkEnabled(String elementLocator, LocatorStrategy locatorType) throws FixtureException {
    WebElement element = getWebElement(elementLocator, locatorType);
    boolean enabled = element.isEnabled();
    logger.debug("Element with locator: {} and locatorType: {} returned for " + "checkEnabled = {}",
            elementLocator, locatorType, enabled);
    return enabled;
}

From source file:org.testeditor.fixture.web.WebFixture.java

License:Open Source License

/**
 * Checks if a given input field is enabled (i.e. editable). The technical
 * locator of the field gets identified by the element list matching the
 * given key.<br />//from  w w w.  jav  a  2s  .com
 * 
 * FitNesse usage..: |assert element|arg1|enabled|[arg2, arg3, ...]| <br />
 * FitNesse example: |assert element|TextboxInRow{0}Col{1}|enabled|[5, 3]|
 * <br />
 * <br />
 * 
 * @param elementListKey
 *            key to find the technical locator
 * @param replaceArgs
 *            values to replace the place holders in the element list entry
 *            with
 * @return true if the field is enabled, otherwise false
 */
public boolean assertElementEnabled(String elementListKey, String... replaceArgs) {
    boolean result = false;

    WebElement element = findWebelement(elementListKey, replaceArgs);

    if (element != null && element.isDisplayed() && element.isEnabled()) {
        result = true;
    }

    return result;
}

From source file:org.usapi.nodetypes.AbstractNode.java

License:Apache License

public boolean nativeIsEnabled() throws USAPIException {
    WebElement webElement = findElement(getLocator());
    return webElement.isEnabled();
}

From source file:org.webtestingexplorer.actions.ActionGenerator.java

License:Open Source License

/**
 * Builds the list of actions to take on a given element.
 *//*from   w  w  w.j av a  2  s .  c  om*/
public Set<Action> generateActionsForElement(WebDriverWrapper driver,
        List<ActionGeneratorConfig> customActionGeneratorConfigs, WebElementWithIdentifier elementWithId) {

    // WebDriver can only interact with visible elements.
    WebElement element = elementWithId.safeGetElement(driver);
    if (!element.isDisplayed() || !element.isEnabled()) {
        return Sets.newHashSet();
    }

    // We set this up to first look for custom action generator configs
    // in the reverse order that they were added. Then if we haven't
    // matched any custom ones, we check the default ones.
    List<ActionGeneratorConfig> allActionGeneratorConfigs = Lists.newArrayList();
    allActionGeneratorConfigs.addAll(customActionGeneratorConfigs);
    Collections.reverse(allActionGeneratorConfigs);
    allActionGeneratorConfigs.addAll(defaultActionGeneratorConfigs);

    for (ActionGeneratorConfig actionConfig : allActionGeneratorConfigs) {
        if (actionConfig.matches(driver, elementWithId)) {
            LOGGER.log(Level.FINE, "Generated actions for element " + elementWithId.getIdentifier());
            return actionConfig.generateActions(driver, elementWithId);
        }
    }
    LOGGER.log(Level.FINE, "No actions generated for element " + elementWithId.getIdentifier());
    return Sets.newHashSet();
}

From source file:org.webtestingexplorer.state.VisibleElementsState.java

License:Open Source License

/**
 * Get information of a WebElement./*ww  w . j ava  2  s  . c  o  m*/
 */
private Map<WebElementIdentifier, Map<String, String>> collectProperties(WebDriverWrapper driver,
        List<WebElementWithIdentifier> elements) {
    Map<WebElementIdentifier, Map<String, String>> allProperties = new HashMap<WebElementIdentifier, Map<String, String>>();

    for (WebElementWithIdentifier elementWithId : elements) {
        // Get all properties
        WebElement e = elementWithId.getElement();
        Map<String, String> properties = new HashMap<String, String>();
        String value = e.getTagName();
        if (value != null) {
            properties.put(TAG_NAME, value);
        }

        value = e.getText();
        if (value != null) {
            properties.put(VALUE, value);
        }

        properties.put(ENABLED, Boolean.toString(e.isEnabled()));
        properties.put(SELECTED, Boolean.toString(e.isSelected()));

        for (String attribute : ELEMENT_ATTRIBUTES) {
            String attributeValue = e.getAttribute(attribute);
            if (attributeValue != null) {
                properties.put(attribute, attributeValue);
            }
        }

        allProperties.put(elementWithId.getIdentifier(), properties);
    }

    return allProperties;
}

From source file:org.xwiki.test.ui.framework.elements.editor.wysiwyg.EditorElement.java

License:Open Source License

/**
 * Waits for the WYSIWYG content editor to load.
 *///from  w  ww .  ja v a2 s.  c  o  m
public EditorElement waitToLoad() {
    try {
        // Either the source tab is present and selected and the plain text area can be edited or the rich text area
        // is not loading (with or without tabs).
        new WebDriverWait(getDriver(), getUtil().getTimeout()).until(new ExpectedCondition<WebElement>() {
            public WebElement apply(WebDriver driver) {
                try {
                    getContainer().findElement(By.xpath(
                            "//div[@class = 'gwt-TabBarItem gwt-TabBarItem-selected']/div[. = 'Source']"));
                    WebElement sourceTextArea = getContainer().findElement(By.className("xPlainTextEditor"));
                    return sourceTextArea.isEnabled() ? sourceTextArea : null;
                } catch (NotFoundException sourceNotFound) {
                    WebElement richTextEditor = getContainer().findElement(By.className("xRichTextEditor"));
                    try {
                        richTextEditor.findElement(By.className("loading"));
                        return null;
                    } catch (NotFoundException loadingNotFound) {
                        return richTextEditor;
                    }
                }
            }
        });
        return this;
    } catch (TimeoutException e) {
        throw new TimeoutException("The WYSIWYG editor failed to load in a decent amount of time!", e);
    }
}

From source file:org.xwiki.test.ui.po.editor.wysiwyg.EditorElement.java

License:Open Source License

/**
 * Waits for the WYSIWYG content editor to load.
 *//*  w  w  w  .  jav  a2s . c o m*/
public EditorElement waitToLoad() {
    getUtil().waitUntilCondition(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver driver) {
            try {
                // Source tab in WYSIWYG editor 2.x syntax
                getContainer(driver).findElement(
                        By.xpath("//div[@class = 'gwt-TabBarItem gwt-TabBarItem-selected']/div[. = 'Source']"));
                WebElement sourceTextArea = getContainer(driver).findElement(By.className("xPlainTextEditor"));
                return sourceTextArea.isEnabled() ? sourceTextArea : null;
            } catch (NotFoundException sourceNotFound) {
                try {
                    // WYSIWYG editor 2.x syntax
                    WebElement richTextEditor = getContainer(driver)
                            .findElement(By.className("xRichTextEditor"));
                    try {
                        richTextEditor.findElement(By.className("loading"));
                        return null;
                    } catch (NotFoundException loadingNotFound) {
                        return richTextEditor;
                    }
                } catch (NotFoundException xRichTextEditorNotFound) {
                    try {
                        // TinyMCE editor 1.x syntax
                        WebElement mceEditor = driver.findElement(By.className("mceEditor"));
                        return mceEditor;
                    } catch (NotFoundException mceNotFound) {
                        return null;
                    }
                }
            }
        }
    });
    return this;
}