com.gargoylesoftware.htmlunit.html.HtmlTextArea Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlTextArea. 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: Window.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
private boolean matches(final Object object) {
    if (object instanceof HtmlEmbed
        || object instanceof HtmlForm
        || object instanceof HtmlImage
        || object instanceof HtmlObject) {
        return true;
    }

    return includeFormFields_
            && (object instanceof HtmlAnchor
                || object instanceof HtmlButton
                || object instanceof HtmlInput
                || object instanceof HtmlMap
                || object instanceof HtmlSelect
                || object instanceof HtmlTextArea);
}
 
Example #2
Source File: MockMvcWebClientCreateTaskTests.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
@Test
	public void testCreateTasks() throws Exception {

		HtmlPage createTaskPage = webClient.getPage("http://localhost:8080/tasks/new");

		HtmlForm form = createTaskPage.getHtmlElementById("form");
		HtmlTextInput nameInput = createTaskPage.getHtmlElementById("name");
		nameInput.setValueAttribute("My first task");
		HtmlTextArea descriptionInput = createTaskPage.getHtmlElementById("description");
		descriptionInput.setText("Description of my first task");
		HtmlButton submit = form.getOneHtmlElementByAttribute("button", "type", "submit");
		HtmlPage taskListPage = submit.click();

		Assertions.assertThat(taskListPage.getUrl().toString()).endsWith("/tasks");
//		String id = taskListPage.getHtmlElementById("todolist").getTextContent();
//		assertThat(id).isEqualTo("123");
//		String summary = newMessagePage.getHtmlElementById("summary").getTextContent();
//		assertThat(summary).isEqualTo("Spring Rocks");
//		String text = newMessagePage.getHtmlElementById("text").getTextContent();
//		assertThat(text).isEqualTo("In case you didn't know, Spring Rocks!");

	}
 
Example #3
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
private boolean matches(final Object object) {
    if (object instanceof HtmlEmbed
        || object instanceof HtmlForm
        || object instanceof HtmlImage
        || object instanceof HtmlObject) {
        return true;
    }
    if (includeFormFields_ && (
            object instanceof HtmlAnchor
            || object instanceof HtmlButton
            || object instanceof HtmlInput
            || object instanceof HtmlMap
            || object instanceof HtmlSelect
            || object instanceof HtmlTextArea)) {
        return true;
    }
    return false;
}
 
Example #4
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the value of the {@code value} attribute.
 * @param value the new value
 */
@Override
public void setValue(final Object value) {
    if (null == value && getBrowserVersion().hasFeature(JS_TEXT_AREA_SET_VALUE_NULL)) {
        ((HtmlTextArea) getDomNodeOrDie()).setText("");
        return;
    }

    ((HtmlTextArea) getDomNodeOrDie()).setText(Context.toString(value));
}
 
Example #5
Source File: HTMLTextAreaElement2Test.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Method type(...) should not trigger onchange!
 * @throws Exception if the test fails
 */
@Test
public void type_onchange() throws Exception {
    final String content
        = "<html><head><title>foo</title>\n"
        + "<script>\n"
        + "  function changed(e) {\n"
        + "    log('changed: ' + e.value);\n"
        + "  }\n"
        + "  function keypressed(e) {\n"
        + "    log('keypressed: ' + e.value);\n"
        + "  }\n"
        + "  function log(msg) {\n"
        + "    document.getElementById('log').value += msg + '; ';\n"
        + "  }\n"
        + "</script></head>\n"
        + "<body>\n"
        + "<form id='form1'>\n"
        + "<textarea id='textArea1' onchange='changed(this)' onkeypress='keypressed(this)'></textarea>\n"
        + "<textarea id='log'></textarea>\n"
        + "</form>\n"
        + "</body></html>";
    final HtmlPage page = loadPageWithAlerts(content);
    final HtmlTextArea textArea = page.getHtmlElementById("textArea1");
    textArea.type("hello");
    page.setFocusedElement(null); // remove focus on textarea to trigger onchange

    final HtmlTextArea log = page.getHtmlElementById("log");
    final String expectation = "keypressed: ; "
        + "keypressed: h; "
        + "keypressed: he; "
        + "keypressed: hel; "
        + "keypressed: hell; "
        + "changed: hello;";
    assertEquals(expectation, log.asText());
}
 
Example #6
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the value of the {@code value} attribute.
 * @param value the new value
 */
@JsxSetter
@Override
public void setValue(final Object value) {
    if (null == value && getBrowserVersion().hasFeature(JS_TEXT_AREA_SET_VALUE_NULL)) {
        ((HtmlTextArea) getDomNodeOrDie()).setText("");
        return;
    }

    ((HtmlTextArea) getDomNodeOrDie()).setText(Context.toString(value));
}
 
Example #7
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the value of the {@code value} attribute.
 * @return the value of the {@code value} attribute
 */
@JsxGetter
@Override
public String getValue() {
    return ((HtmlTextArea) getDomNodeOrDie()).getText();
}
 
Example #8
Source File: ComputedCSSStyleDeclaration.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the element's calculated height taking relevant CSS into account, but <b>not</b> the element's child
 * elements.
 *
 * @return the element's calculated height taking relevant CSS into account, but <b>not</b> the element's child
 *         elements
 */
private int getEmptyHeight() {
    if (height2_ != null) {
        return height2_.intValue();
    }

    final DomNode node = getElement().getDomNodeOrDie();
    if (!node.mayBeDisplayed()) {
        height2_ = Integer.valueOf(0);
        return 0;
    }

    if (NONE.equals(getDisplay())) {
        height2_ = Integer.valueOf(0);
        return 0;
    }

    final Element elem = getElement();
    final int windowHeight = elem.getWindow().getWebWindow().getInnerHeight();

    if (elem instanceof HTMLBodyElement) {
        height2_ = windowHeight;
        return windowHeight;
    }

    final boolean explicitHeightSpecified = !super.getHeight().isEmpty();

    int defaultHeight;
    if (node instanceof HtmlDivision && StringUtils.isBlank(node.getTextContent())) {
        defaultHeight = 0;
    }
    else if (elem.getFirstChild() == null) {
        if (node instanceof HtmlRadioButtonInput || node instanceof HtmlCheckBoxInput) {
            defaultHeight = 13;
        }
        else if (node instanceof HtmlButton) {
            defaultHeight = 20;
        }
        else if (node instanceof HtmlInput && !(node instanceof HtmlHiddenInput)) {
            final BrowserVersion browser = getBrowserVersion();
            if (browser.hasFeature(JS_CLIENTHIGHT_INPUT_17)) {
                defaultHeight = 17;
            }
            else if (browser.hasFeature(JS_CLIENTHIGHT_INPUT_21)) {
                defaultHeight = 21;
            }
            else {
                defaultHeight = 20;
            }
        }
        else if (node instanceof HtmlSelect) {
            defaultHeight = 20;
        }
        else if (node instanceof HtmlTextArea) {
            defaultHeight = 49;
        }
        else if (node instanceof HtmlInlineFrame) {
            defaultHeight = 154;
        }
        else {
            defaultHeight = 0;
        }
    }
    else {
        defaultHeight = getBrowserVersion().getFontHeight(getFontSize());
        if (node instanceof HtmlDivision) {
            defaultHeight *= StringUtils.countMatches(node.asText(), '\n') + 1;
        }
    }

    final int defaultWindowHeight = elem instanceof HTMLCanvasElement ? 150 : windowHeight;

    int height = pixelValue(elem, new CssValue(defaultHeight, defaultWindowHeight) {
        @Override public String get(final ComputedCSSStyleDeclaration style) {
            final Element element = style.getElement();
            if (element instanceof HTMLBodyElement) {
                return String.valueOf(element.getWindow().getWebWindow().getInnerHeight());
            }
            return style.getStyleAttribute(HEIGHT, true);
        }
    });

    if (height == 0 && !explicitHeightSpecified) {
        height = defaultHeight;
    }

    height2_ = Integer.valueOf(height);
    return height;
}
 
Example #9
Source File: HTMLFormElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the value of the property {@code elements}.
 * @return the value of this property
 */
@JsxGetter
public HTMLCollection getElements() {
    final HtmlForm htmlForm = getHtmlForm();

    return new HTMLCollection(htmlForm, false) {
        private boolean filterChildrenOfNestedForms_;

        @Override
        protected List<DomNode> computeElements() {
            final List<DomNode> response = super.computeElements();
            // it would be more performant to avoid iterating through
            // nested forms but as it is a corner case of ill formed HTML
            // the needed refactoring would take too much time
            // => filter here and not in isMatching as it won't be needed in most
            // of the cases
            if (filterChildrenOfNestedForms_) {
                for (final Iterator<DomNode> iter = response.iterator(); iter.hasNext();) {
                    final HtmlElement field = (HtmlElement) iter.next();
                    if (field.getEnclosingForm() != htmlForm) {
                        iter.remove();
                    }
                }
            }
            response.addAll(htmlForm.getLostChildren());
            return response;
        }

        @Override
        protected Object getWithPreemption(final String name) {
            return HTMLFormElement.this.getWithPreemption(name);
        }

        @Override
        public EffectOnCache getEffectOnCache(final HtmlAttributeChangeEvent event) {
            return EffectOnCache.NONE;
        }

        @Override
        protected boolean isMatching(final DomNode node) {
            if (node instanceof HtmlForm) {
                filterChildrenOfNestedForms_ = true;
                return false;
            }

            return node instanceof HtmlInput || node instanceof HtmlButton
                    || node instanceof HtmlTextArea || node instanceof HtmlSelect;
        }
    };
}
 
Example #10
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the {@code placeholder} attribute.
 * @param placeholder the new {@code placeholder} value
 */
@JsxSetter
public void setPlaceholder(final String placeholder) {
    ((HtmlTextArea) getDomNodeOrDie()).setPlaceholder(placeholder);
}
 
Example #11
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@code placeholder} attribute.
 * @return the {@code placeholder} attribute
 */
@JsxGetter
public String getPlaceholder() {
    return ((HtmlTextArea) getDomNodeOrDie()).getPlaceholder();
}
 
Example #12
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the value of {@code readOnly} attribute.
 * @param readOnly the new value
 */
@JsxSetter
public void setReadOnly(final boolean readOnly) {
    ((HtmlTextArea) getDomNodeOrDie()).setReadOnly(readOnly);
}
 
Example #13
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value of {@code readOnly} attribute.
 * @return the readOnly attribute
 */
@JsxGetter
public boolean isReadOnly() {
    return ((HtmlTextArea) getDomNodeOrDie()).isReadOnly();
}
 
Example #14
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Selects this element.
 */
@JsxFunction
public void select() {
    ((HtmlTextArea) getDomNodeOrDie()).select();
}
 
Example #15
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the value of {@code selectionEnd} attribute.
 * @param end selection end
 */
@JsxSetter
public void setSelectionEnd(final int end) {
    ((HtmlTextArea) getDomNodeOrDie()).setSelectionEnd(end);
}
 
Example #16
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value of {@code selectionEnd} attribute.
 * @return the selection end
 */
@JsxGetter
public int getSelectionEnd() {
    return ((HtmlTextArea) getDomNodeOrDie()).getSelectionEnd();
}
 
Example #17
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the value of {@code selectionStart} attribute.
 * @param start selection start
 */
@JsxSetter
public void setSelectionStart(final int start) {
    ((HtmlTextArea) getDomNodeOrDie()).setSelectionStart(start);
}
 
Example #18
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value of {@code selectionStart} attribute.
 * @return the selection start
 */
@JsxGetter
public int getSelectionStart() {
    return ((HtmlTextArea) getDomNodeOrDie()).getSelectionStart();
}
 
Example #19
Source File: HTMLTextAreaElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the value of the {@code value} attribute.
 * @return the value of the {@code value} attribute
 */
@Override
public String getValue() {
    return ((HtmlTextArea) getDomNodeOrDie()).getText();
}
 
Example #20
Source File: ComputedCSSStyleDeclaration.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the element's calculated height taking relevant CSS into account, but <b>not</b> the element's child
 * elements.
 *
 * @return the element's calculated height taking relevant CSS into account, but <b>not</b> the element's child
 *         elements
 */
private int getEmptyHeight() {
    if (height2_ != null) {
        return height2_.intValue();
    }

    final DomNode node = getElement().getDomNodeOrDie();
    if (!node.mayBeDisplayed()) {
        height2_ = Integer.valueOf(0);
        return 0;
    }

    if ("none".equals(getDisplay())) {
        height2_ = Integer.valueOf(0);
        return 0;
    }

    final Element elem = getElement();
    final int windowHeight = elem.getWindow().getWebWindow().getInnerHeight();

    if (elem instanceof HTMLBodyElement) {
        height2_ = windowHeight;
        return windowHeight;
    }

    final boolean explicitHeightSpecified = !super.getHeight().isEmpty();

    int defaultHeight;
    if (node instanceof HtmlDivision && StringUtils.isBlank(node.getTextContent())) {
        defaultHeight = 0;
    }
    else if (elem.getFirstChild() == null) {
        if (node instanceof HtmlRadioButtonInput || node instanceof HtmlCheckBoxInput) {
            defaultHeight = 13;
        }
        else if (node instanceof HtmlButton) {
            defaultHeight = 20;
        }
        else if (node instanceof HtmlInput && !(node instanceof HtmlHiddenInput)) {
            if (getBrowserVersion().hasFeature(JS_CLIENTHIGHT_INPUT_17)) {
                defaultHeight = 17;
            }
            else {
                defaultHeight = 21;
            }
        }
        else if (node instanceof HtmlSelect) {
            defaultHeight = 20;
        }
        else if (node instanceof HtmlTextArea) {
            defaultHeight = 49;
        }
        else if (node instanceof HtmlInlineFrame) {
            defaultHeight = 154;
        }
        else {
            defaultHeight = 0;
        }
    }
    else {
        defaultHeight = getBrowserVersion().getFontHeight(getFontSize());
        if (node instanceof HtmlDivision) {
            defaultHeight *= StringUtils.countMatches(node.asText(), '\n') + 1;
        }
    }

    final int defaultWindowHeight = elem instanceof HTMLCanvasElement ? 150 : windowHeight;

    int height = pixelValue(elem, new CssValue(defaultHeight, defaultWindowHeight) {
        @Override public String get(final ComputedCSSStyleDeclaration style) {
            final Element element = style.getElement();
            if (element instanceof HTMLBodyElement) {
                return String.valueOf(element.getWindow().getWebWindow().getInnerHeight());
            }
            return style.getStyleAttribute(HEIGHT, true);
        }
    });

    if (height == 0 && !explicitHeightSpecified) {
        height = defaultHeight;
    }

    height2_ = Integer.valueOf(height);
    return height;
}
 
Example #21
Source File: HTMLFormElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the value of the property {@code elements}.
 * @return the value of this property
 */
@JsxGetter
public HTMLCollection getElements() {
    final HtmlForm htmlForm = getHtmlForm();

    return new HTMLCollection(htmlForm, false) {
        private boolean filterChildrenOfNestedForms_;

        @Override
        protected List<DomNode> computeElements() {
            final List<DomNode> response = super.computeElements();
            // it would be more performant to avoid iterating through
            // nested forms but as it is a corner case of ill formed HTML
            // the needed refactoring would take too much time
            // => filter here and not in isMatching as it won't be needed in most
            // of the cases
            if (filterChildrenOfNestedForms_) {
                for (final Iterator<DomNode> iter = response.iterator(); iter.hasNext();) {
                    final HtmlElement field = (HtmlElement) iter.next();
                    if (field.getEnclosingForm() != htmlForm) {
                        iter.remove();
                    }
                }
            }
            response.addAll(htmlForm.getLostChildren());
            return response;
        }

        @Override
        protected Object getWithPreemption(final String name) {
            return HTMLFormElement.this.getWithPreemption(name);
        }

        @Override
        public EffectOnCache getEffectOnCache(final HtmlAttributeChangeEvent event) {
            return EffectOnCache.NONE;
        }

        @Override
        protected boolean isMatching(final DomNode node) {
            if (node instanceof HtmlForm) {
                filterChildrenOfNestedForms_ = true;
                return false;
            }

            return node instanceof HtmlInput || node instanceof HtmlButton
                    || node instanceof HtmlTextArea || node instanceof HtmlSelect;
        }
    };
}
 
Example #22
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the {@code placeholder} attribute.
 * @param placeholder the new {@code placeholder} value
 */
@JsxSetter
public void setPlaceholder(final String placeholder) {
    ((HtmlTextArea) getDomNodeOrDie()).setPlaceholder(placeholder);
}
 
Example #23
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@code placeholder} attribute.
 * @return the {@code placeholder} attribute
 */
@JsxGetter
public String getPlaceholder() {
    return ((HtmlTextArea) getDomNodeOrDie()).getPlaceholder();
}
 
Example #24
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the value of {@code readOnly} attribute.
 * @param readOnly the new value
 */
@JsxSetter
public void setReadOnly(final boolean readOnly) {
    ((HtmlTextArea) getDomNodeOrDie()).setReadOnly(readOnly);
}
 
Example #25
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value of {@code readOnly} attribute.
 * @return the readOnly attribute
 */
@JsxGetter
public boolean isReadOnly() {
    return ((HtmlTextArea) getDomNodeOrDie()).isReadOnly();
}
 
Example #26
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Selects this element.
 */
@JsxFunction
public void select() {
    ((HtmlTextArea) getDomNodeOrDie()).select();
}
 
Example #27
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the value of {@code selectionEnd} attribute.
 * @param end selection end
 */
@JsxSetter
public void setSelectionEnd(final int end) {
    ((HtmlTextArea) getDomNodeOrDie()).setSelectionEnd(end);
}
 
Example #28
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value of {@code selectionEnd} attribute.
 * @return the selection end
 */
@JsxGetter
public int getSelectionEnd() {
    return ((HtmlTextArea) getDomNodeOrDie()).getSelectionEnd();
}
 
Example #29
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the value of {@code selectionStart} attribute.
 * @param start selection start
 */
@JsxSetter
public void setSelectionStart(final int start) {
    ((HtmlTextArea) getDomNodeOrDie()).setSelectionStart(start);
}
 
Example #30
Source File: HTMLTextAreaElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value of {@code selectionStart} attribute.
 * @return the selection start
 */
@JsxGetter
public int getSelectionStart() {
    return ((HtmlTextArea) getDomNodeOrDie()).getSelectionStart();
}