Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlTextArea

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlTextArea. These examples are extracted from open source projects. 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 Project: htmlunit   Source File: Window.java    License: 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 Project: HtmlUnit-Android   Source File: Window.java    License: 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 3
@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 4
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 5
Source Project: htmlunit   Source File: HTMLTextAreaElement2Test.java    License: 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 Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 7
Source Project: htmlunit   Source File: ComputedCSSStyleDeclaration.java    License: 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 8
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 9
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 10
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 11
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 12
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 13
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Selects this element.
 */
@JsxFunction
public void select() {
    ((HtmlTextArea) getDomNodeOrDie()).select();
}
 
Example 14
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 15
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 16
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 17
Source Project: htmlunit   Source File: HTMLTextAreaElement.java    License: 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 18
Source Project: htmlunit   Source File: HTMLFormElement.java    License: 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 19
/**
 * 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 20
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 21
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 22
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 23
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 24
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 25
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Selects this element.
 */
@JsxFunction
public void select() {
    ((HtmlTextArea) getDomNodeOrDie()).select();
}
 
Example 26
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 27
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 28
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 29
Source Project: HtmlUnit-Android   Source File: HTMLTextAreaElement.java    License: 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 30
Source Project: HtmlUnit-Android   Source File: HTMLFormElement.java    License: 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;
        }
    };
}