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.aludratest.service.gui.web.selenium.selenium2.Selenium2Facade.java

License:Apache License

private boolean isEditable(WebElement element) {
    for (int i = 0; i < MAX_RETRIES_ON_STALE_ELEMENT; i++) {
        try {/* www .  ja v a  2s  .  c om*/
            if (!element.isEnabled()) {
                return false;
            }
            String tagName = element.getTagName().toLowerCase();
            if (!EDITABLE_ELEMENTS.contains(tagName)) {
                return false;
            }
            if ("input".equals(tagName)) {
                String readonly = element.getAttribute("readonly");
                return (readonly == null || "false".equals(readonly));
            } else {
                return true;
            }
        } catch (StaleElementReferenceException e) {
            // ignore this and retry in the next loop iteration
        }
    }

    // assert that it is gone forever. This means "not editable".
    return false;
}

From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java

License:Open Source License

private boolean isEnabled(String locator) {
    WebElement el = finder.find(locator);

    if (!isFormElement(el)) {
        throw new AssertionError(String.format("Element %s is not an input.", locator));
    }/*from w  ww .j ava2s . c o m*/

    if (!el.isEnabled()) {
        return false;
    }

    String readOnly = el.getAttribute("readonly");

    if (readOnly != null && (readOnly.equalsIgnoreCase("readonly") || readOnly.equalsIgnoreCase("true"))) {
        return false;
    }

    return true;
}

From source file:org.mule.modules.selenium.SeleniumModule.java

License:Open Source License

/**
 * Is the element currently enabled or not? This will generally return true for everything but
 * disabled input elements./*w  w w .  j a v  a  2s  .c  om*/
 * <p/>
 * {@sample.xml ../../../doc/mule-module-selenium.xml.sample selenium:is-enabled}
 *
 * @param element Element located at the payload of the message
 * @return True if the element is enabled, false otherwise.
 */
@Processor
public boolean isEnabled(@Payload WebElement element) {
    return element.isEnabled();
}

From source file:org.musetest.selenium.conditions.ElementEnabledCondition.java

License:Open Source License

@Override
public Boolean resolveValue(MuseExecutionContext context) throws ValueSourceResolutionError {
    WebElement element = resolveElementSource(context, true);
    boolean enabled = element.isEnabled();
    context.raiseEvent(ValueSourceResolvedEventType.create(getDescription(), enabled));
    return enabled;
}

From source file:org.nuxeo.ftest.cap.ITWorkspaceTest.java

License:Apache License

@Test
public void testDeleteWorkspace() throws Exception {
    // First create workspace as Administrator
    login().createWorkspace(WORKSPACE_TITLE, WORKSPACE_DESCRIPTION).createNote("Note to delete",
            "Note description to delete", false, null);
    logout();//from w  w w  .j av a  2 s . c  o m

    // Delete it as Test User
    DocumentBasePage workspacesPage = loginAsTestUser().goToWorkspaces().goToDocumentWorkspaces();
    ContentTabSubPage contentTabPage = workspacesPage.getContentTab();
    contentTabPage.getContentView().selectByTitle(WORKSPACE_TITLE);
    WebElement deleteLink = driver.findElementById(
            "document_content_buttons:nxw_CURRENT_SELECTION_TRASH_form:nxw_CURRENT_SELECTION_TRASH");
    assertTrue(deleteLink.isEnabled());
    assertTrue(driver.findElementById(
            "document_content_buttons:nxw_CURRENT_SELECTION_ADDTOLIST_form:nxw_CURRENT_SELECTION_ADDTOLIST")
            .isEnabled());
    // Delete the workspace then cancel it on confirmation
    deleteLink.click();
    Alert alert = driver.switchTo().alert();
    assertEquals("Delete selected document(s)?", alert.getText());
    alert.dismiss();
    // De-select workspace to delete as removeDocument() select it
    contentTabPage.getContentView().unselectByTitle(WORKSPACE_TITLE);
    contentTabPage = contentTabPage.removeDocument(WORKSPACE_TITLE).asPage(ContentTabSubPage.class);
    assertFalse(contentTabPage.getChildDocumentRows().stream()
            .filter(element -> WORKSPACE_TITLE.equals(element.getText())).findAny().isPresent());

}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

/**
 * Waits until an element is enabled, with a timeout.
 *
 * @param element the element//from   w  w  w . j ava 2s.  c  o  m
 * @param timeout the timeout in milliseconds
 */
public static void waitUntilEnabled(final WebElement element, int timeout) throws NotFoundException {
    Clock clock = new SystemClock();
    long end = clock.laterBy(timeout);
    while (clock.isNowBefore(end)) {
        if (element.isEnabled()) {
            return;
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            // ignore
        }
    }
    throw new NotFoundException("Element not enabled after timeout: " + element);
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

/**
 * Waits until an element is enabled, with a timeout.
 *
 * @param element the element/*from   www . j a v a  2s  . co  m*/
 * @param timeout the timeout in milliseconds
 */
public static void waitUntilEnabled(final WebElement element, int timeout) throws NotFoundException {
    FluentWait<WebDriver> wait = getFluentWait();
    wait.withTimeout(timeout, TimeUnit.MILLISECONDS);
    Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            return element.isEnabled();
        }
    };
    try {
        wait.until(function);
    } catch (TimeoutException e) {
        throw new NotFoundException("Element not enabled after timeout: " + element);
    }
}

From source file:org.nuxeo.functionaltests.pages.search.DefaultSearchSubPage.java

License:Apache License

public void selectPath(String path) {
    assert (path != null && !path.isEmpty() && path.charAt(0) == '/');
    openPathPopupButton.click();/*  w ww.  j a  va  2  s.  co  m*/
    Locator.waitUntilGivenFunction(new Function<WebDriver, Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                WebElement tree = driver.findElement(By.id(TREE_PATH_ID));
                return tree.isDisplayed();
            } catch (NoSuchElementException e) {
                return false;
            }
        }
    });
    if (path.length() == 1) {
        AjaxRequestManager a = new AjaxRequestManager(driver);
        a.watchAjaxRequests();
        driver.findElement(By.id(TREE_PATH_ID)).findElement(By.linkText("/")).click();
        a.waitForAjaxRequests();
        return;
    } else {
        AjaxRequestManager a = new AjaxRequestManager(driver);
        a.watchAjaxRequests();
        driver.findElement(By.id(TREE_PATH_ID)).findElement(By.linkText("/"))
                .findElement(By.xpath(EXPAND_XPATH)).click();
        a.waitForAjaxRequests();
    }
    String[] pathArray = path.substring(1).split("/");
    int i = 0;
    for (; i < pathArray.length - 1; i++) {
        AjaxRequestManager a = new AjaxRequestManager(driver);
        a.watchAjaxRequests();
        driver.findElement(By.id(TREE_PATH_ID)).findElement(By.linkText(pathArray[i]))
                .findElement(By.xpath(EXPAND_XPATH)).click();
        a.waitForAjaxRequests();
    }
    AjaxRequestManager a = new AjaxRequestManager(driver);
    a.watchAjaxRequests();
    driver.findElement(By.id(TREE_PATH_ID)).findElement(By.linkText(pathArray[i])).click();
    a.waitForAjaxRequests();
    AbstractPage.closeFancyBox();
    Locator.waitUntilGivenFunction(new Function<WebDriver, Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                WebElement btn = driver.findElement(By.id("fancybox-overlay"));
                return !btn.isDisplayed() || !btn.isEnabled();
            } catch (NoSuchElementException e) {
                return false;
            }
        }
    });
}

From source file:org.olat.selenium.page.course.CourseWizardPage.java

License:Apache License

/**
 * Next/* w ww  .j a v a  2 s  .  c  o  m*/
 * @return this
 */
public CourseWizardPage next() {
    WebElement next = browser.findElement(nextBy);
    Assert.assertTrue(next.isDisplayed());
    Assert.assertTrue(next.isEnabled());
    next.click();
    OOGraphene.waitBusy(browser);
    OOGraphene.closeBlueMessageWindow(browser);
    return this;
}

From source file:org.olat.selenium.page.course.CourseWizardPage.java

License:Apache License

/**
 * Finish the wizard// ww w  . j  a v  a 2 s .com
 * @return this
 */
public CourseWizardPage finish() {
    WebElement finish = browser.findElement(finishBy);
    Assert.assertTrue(finish.isDisplayed());
    Assert.assertTrue(finish.isEnabled());
    finish.click();
    OOGraphene.waitBusy(browser);
    OOGraphene.closeBlueMessageWindow(browser);
    return this;
}