Java Code Examples for org.openqa.selenium.WebElement#isEnabled()

The following examples show how to use org.openqa.selenium.WebElement#isEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpectedConditions.java    From selenium with Apache License 2.0 6 votes vote down vote up
/**
 * An expectation for checking an element is visible and enabled such that you can click it.
 *
 * @param locator used to find the element
 * @return the WebElement once it is located and clickable (visible and enabled)
 */
public static ExpectedCondition<WebElement> elementToBeClickable(final By locator) {
  return new ExpectedCondition<WebElement>() {
    @Override
    public WebElement apply(WebDriver driver) {
      WebElement element = visibilityOfElementLocated(locator).apply(driver);
      try {
        if (element != null && element.isEnabled()) {
          return element;
        }
        return null;
      } catch (StaleElementReferenceException e) {
        return null;
      }
    }

    @Override
    public String toString() {
      return "element to be clickable: " + locator;
    }
  };
}
 
Example 2
Source File: RealHtmlCheckBox.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Check the check box
 */
@Override
@PublicAtsApi
public void check() {

    new RealHtmlElementState(this).waitToBecomeExisting();

    WebElement checkBoxElement = RealHtmlElementLocator.findElement(this);
    if (!checkBoxElement.isEnabled()) {
        throw new UnsupportedOperationException("You may not check a disabled element."
                                                + toString());
    }
    if (!checkBoxElement.isSelected()) {
        checkBoxElement.click();
    }

    UiEngineUtilities.sleep();
}
 
Example 3
Source File: RealHtmlCheckBox.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Uncheck the check box
 */
@Override
@PublicAtsApi
public void unCheck() {

    new RealHtmlElementState(this).waitToBecomeExisting();

    WebElement checkBoxElement = RealHtmlElementLocator.findElement(this);
    if (!checkBoxElement.isEnabled()) {
        throw new UnsupportedOperationException("You may not uncheck a disabled element."
                                                + toString());
    }
    if (checkBoxElement.isSelected()) {
        checkBoxElement.click();
    }

    UiEngineUtilities.sleep();
}
 
Example 4
Source File: ClickOn.java    From NetDiscovery with Apache License 2.0 6 votes vote down vote up
@Override
public SeleniumAction perform(WebDriver driver) {

    List<WebElement> elements = driver.findElements(by);
    if (elements != null) {
        for (WebElement currentElement : elements) {
            if (currentElement.isEnabled() &&
                    currentElement.isDisplayed() &&
                    currentElement.getSize().getHeight() > 0 &&
                    currentElement.getSize().getWidth() > 0) {

                currentElement.click();

                return this;
            }
        }
    }
    return this;
}
 
Example 5
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that waits until an element becomes
 * enabled (generally applies to input elements).
 */
public static ExpectedCondition<Boolean> elementToBeEnabled(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                if (element.isEnabled()) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        public String toString() {
            return "element to be enabled: " + element.toString();
        }
    };
}
 
Example 6
Source File: LocatingElementHandlerTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotRepeatedlyLookUpElementsMarkedAsNeverChanging() {
  final ElementLocator locator = mock(ElementLocator.class);
  final WebElement element = mock(WebElement.class);

  when(locator.findElement()).thenReturn(element);

  LocatingElementHandler handler = new LocatingElementHandler(locator);
  WebElement proxy =
      (WebElement) Proxy.newProxyInstance(getClass().getClassLoader(),
          new Class[] {WebElement.class}, handler);

  proxy.isEnabled();
  proxy.sendKeys("Cheese");

  verify(element).isEnabled();
  verify(element).sendKeys("Cheese");
}
 
Example 7
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
private boolean moveRubricCol(int qnNumber, int colNumber, boolean isMoveLeft) {
    String elemId;

    if (isMoveLeft) {
        elemId = Const.ParamsNames.FEEDBACK_QUESTION_RUBRIC_MOVE_COL_LEFT + "-" + qnNumber + "-" + colNumber;
    } else {
        elemId = Const.ParamsNames.FEEDBACK_QUESTION_RUBRIC_MOVE_COL_RIGHT + "-" + qnNumber + "-" + colNumber;
    }

    WebElement moveColButton = browser.driver.findElement(By.id(elemId));

    if (moveColButton.isEnabled()) {
        click(moveColButton);

        return true;
    }

    return false;
}
 
Example 8
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
public boolean isAllFeedbackPathOptionsEnabledForNewQuestion() {
    List<WebElement> options = browser.driver.findElements(By.cssSelector("#givertype-" + NEW_QUESTION_NUM + " option"));
    options.addAll(browser.driver.findElements(By.cssSelector("#recipienttype-" + NEW_QUESTION_NUM + " option")));
    for (WebElement option : options) {
        if (!option.isEnabled()) {
            return false;
        }
    }
    return true;
}
 
Example 9
Source File: RealHtmlRadioList.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
/**
 * set the selected value
 *
 * @param value the value to select(this is the 'value' attribute of the radio button)
 */
@PublicAtsApi
public void select(
                    String value ) {

    new RealHtmlElementState(this).waitToBecomeExisting();

    WebElement element = RealHtmlElementLocator.findElement(this, "[@value='" + value + "']", true);
    if (!element.isEnabled()) {
        throw new UnsupportedOperationException("You may not select a disabled element." + toString());
    }
    element.click();

    UiEngineUtilities.sleep();
}
 
Example 10
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean _isEnabled()
{
  WebElement webElement = (WebElement) getElement();

  if (webElement == null)
    throw new ScriptException("Element was found but not enabled");

  boolean returnValue = webElement.isEnabled();
  if (returnValue)
    getActionProvider().getSupportedTimers((DeviceWebDriver) getWebDriver(), getExecutionContext().getTimerName(), getExecutionContext(), null);

  return returnValue;

}
 
Example 11
Source File: ElementAction.java    From PatatiumWebUi with Apache License 2.0 5 votes vote down vote up
/**
 * 判断元素是否显示
 * @param locator 元素定位信息
 * @return  返回boolean true显示,false隐藏
 */
public boolean isElementDisplayed(Locator locator)
{
	ElementAction action =new ElementAction();
	WebElement webElement=action.findElement(locator);
	webElement.isEnabled();
	log.info("元素显示状态为:"+ webElement.isDisplayed());
	return webElement.isDisplayed();
}
 
Example 12
Source File: IsEditable.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
protected Boolean handleSeleneseCommand(WebDriver driver, String locator, String value) {
  WebElement element = finder.findElement(driver, locator);
  String tagName = element.getTagName().toLowerCase();
  boolean acceptableTagName = "input".equals(tagName) || "select".equals(tagName);
  String readonly = "";
  if ("input".equals(tagName)) {
    readonly = element.getAttribute("readonly");
    if (readonly == null || "false".equals(readonly)) {
      readonly = "";
    }
  }

  return element.isEnabled() && acceptableTagName && "".equals(readonly);
}
 
Example 13
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the texts of all available options for the supplied select element.
 * @param element select element to find options for.
 * @return text per option.
 */
public ArrayList<String> getAvailableOptions(WebElement element) {
    ArrayList<String> result = null;
    if (isInteractable(element)
            && "select".equalsIgnoreCase(element.getTagName())) {
        result = new ArrayList<String>();
        List<WebElement> options = element.findElements(By.tagName("option"));
        for (WebElement option : options) {
            if (option.isEnabled()) {
                result.add(option.getText());
            }
        }
    }
    return result;
}
 
Example 14
Source File: AppPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Clears any kind of editable element, but without firing the {@code change} event (unlike {@link WebElement#clear()}).
 * Avoid using this method if {@link WebElement#clear()} meets the requirements as this method depends on implementation
 * details.
 */
private Map<String, Object> clearWithoutEvents(WebElement element) {
    // This method is a close mirror of HtmlUnitWebElement#clear(), except that events are not handled. Note that
    // HtmlUnitWebElement is mirrored as opposed to RemoteWebElement (which is used with actual browsers) for convenience
    // and the implementation can differ.
    checkNotNull(element);

    // Adapted from ExpectedConditions#stalenessOf which forces a staleness check. This allows a meaningful
    // StaleElementReferenceException to be thrown rather than just getting a boolean from ExpectedConditions.
    element.isEnabled();

    // Fail safe in case the implementation of staleness checks is changed
    if (isExpectedCondition(ExpectedConditions.stalenessOf(element))) {
        throw new AssertionError(
                "Element is stale but should have been caught earlier by element.isEnabled().");
    }

    @SuppressWarnings("unchecked")
    Map<String, Object> result = (Map<String, Object>) executeScript(
            "const element = arguments[0];"
                    + "if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {"
                    + "   if (element.readOnly) {"
                    + "       return { "
                    + "           errors: {"
                    + "               detail: 'You may only edit editable elements'"
                    + "           }"
                    + "       };"
                    + "   }"
                    + "   if (element.disabled) {"
                    + "       return { "
                    + "           errors: {"
                    + "               detail: 'You may only interact with enabled elements'"
                    + "           }"
                    + "       };"
                    + "   }"
                    + "   element.value='';"
                    + "} else if (element.isContentEditable) {"
                    + "   while (element.firstChild) {"
                    + "       element.removeChild(element.firstChild);"
                    + "   }"
                    + "}"
                    + "return { "
                    + "   data: {"
                    + "       detail: 'Success'"
                    + "   }"
                    + "};", element);
    return result;
}
 
Example 15
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public boolean isSelectQuestionNumberEnabled(int qnNumber) {
    WebElement qnNumSelect = getSelectQuestionNumberDropdown(qnNumber);
    return qnNumSelect.isEnabled();
}
 
Example 16
Source File: InstructorFeedbackEditPage.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
public boolean isQuestionEnabled(int qnNumber) {
    WebElement questionTextArea = browser.driver.findElement(By.id("questiontext-" + qnNumber));
    return questionTextArea.isEnabled();
}
 
Example 17
Source File: SmartWebElement.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public boolean isEnabled() {
    WebElement e = getElement();
    return e.isEnabled();
}
 
Example 18
Source File: EnabledMatcher.java    From matchers-java with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSafely(WebElement element) {
    return element.isEnabled();
}
 
Example 19
Source File: ElementStateProvider.java    From aquality-selenium-java with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean isElementEnabled(WebElement element) {
    return element.isEnabled() && !element.getAttribute(Attributes.CLASS.toString()).contains("disabled");
}
 
Example 20
Source File: IsInteractableFilter.java    From hsac-fitnesse-fixtures with Apache License 2.0 2 votes vote down vote up
/**
 * Checks whether element is interactable.
 * @param element element to check.
 * @return true for interactable elements, false otherwise.
 */
public static boolean mayPass(WebElement element) {
    return IsDisplayedFilter.mayPass(element) && element.isEnabled();
}