Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlElement#setAttribute()

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlElement#setAttribute() . 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: DOMStringMap.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (!(ScriptableObject.getTopLevelScope(this) instanceof Window) || getWindow().getWebWindow() == null) {
        super.put(name, start, value);
    }
    else {
        final HtmlElement e = (HtmlElement) getDomNodeOrNull();
        if (e != null) {
            e.setAttribute("data-" + decamelize(name), Context.toString(value));
        }
    }
}
 
Example 2
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets whether or not to disable this element.
 * @param disabled True if this is to be disabled
 */
@JsxSetter(IE)
public void setDisabled(final boolean disabled) {
    final HtmlElement element = getDomNodeOrDie();
    if (disabled) {
        element.setAttribute("disabled", "disabled");
    }
    else {
        element.removeAttribute("disabled");
    }
}
 
Example 3
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * An IE-only method which copies all custom attributes from the specified source element
 * to this element.
 * @param source the source element from which to copy the custom attributes
 * @param preserveIdentity if {@code false}, the <tt>name</tt> and <tt>id</tt> attributes are not copied
 */
@JsxFunction(IE)
public void mergeAttributes(final HTMLElement source, final Object preserveIdentity) {
    final HtmlElement src = source.getDomNodeOrDie();
    final HtmlElement target = getDomNodeOrDie();

    // Merge ID and name if we aren't preserving identity.
    if (preserveIdentity instanceof Boolean && !((Boolean) preserveIdentity).booleanValue()) {
        target.setId(src.getId());
        target.setAttribute("name", src.getAttributeDirect("name"));
    }
}
 
Example 4
Source File: DOMStringMap.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (!(ScriptableObject.getTopLevelScope(this) instanceof Window) || getWindow().getWebWindow() == null) {
        super.put(name, start, value);
    }
    else {
        final HtmlElement e = (HtmlElement) getDomNodeOrNull();
        if (e != null) {
            e.setAttribute("data-" + decamelize(name), Context.toString(value));
        }
    }
}
 
Example 5
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets whether or not to disable this element.
 * @param disabled True if this is to be disabled
 */
@JsxSetter(IE)
public void setDisabled(final boolean disabled) {
    final HtmlElement element = getDomNodeOrDie();
    if (disabled) {
        element.setAttribute("disabled", "disabled");
    }
    else {
        element.removeAttribute("disabled");
    }
}
 
Example 6
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * An IE-only method which copies all custom attributes from the specified source element
 * to this element.
 * @param source the source element from which to copy the custom attributes
 * @param preserveIdentity if {@code false}, the <tt>name</tt> and <tt>id</tt> attributes are not copied
 */
@JsxFunction(IE)
public void mergeAttributes(final HTMLElement source, final Object preserveIdentity) {
    final HtmlElement src = source.getDomNodeOrDie();
    final HtmlElement target = getDomNodeOrDie();

    // Merge ID and name if we aren't preserving identity.
    if (preserveIdentity instanceof Boolean && !((Boolean) preserveIdentity).booleanValue()) {
        target.setId(src.getId());
        target.setAttribute("name", src.getAttributeDirect("name"));
    }
}
 
Example 7
Source File: HTMLImageElement.java    From htmlunit with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the {@code src} attribute.
 * @param src the {@code src} attribute value
 */
@JsxSetter
public void setSrc(final String src) {
    final HtmlElement img = getDomNodeOrDie();
    img.setAttribute(DomElement.SRC_ATTRIBUTE, src);
}
 
Example 8
Source File: HTMLImageElement.java    From HtmlUnit-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the {@code src} attribute.
 * @param src the {@code src} attribute value
 */
@JsxSetter
public void setSrc(final String src) {
    final HtmlElement img = getDomNodeOrDie();
    img.setAttribute("src", src);
}
 
Example 9
Source File: JmxWebHandlerTest.java    From simplejmx with ISC License 4 votes vote down vote up
@Test(timeout = 10000)
public void testSimple() throws Exception {
	WebClient webClient = new WebClient();
	HtmlPage page = webClient.getPage("http://" + WEB_SERVER_NAME + ":" + WEB_SERVER_PORT);
	assertTrue(page.asText().contains("JMX Domains"));

	String domain = "java.lang";
	HtmlAnchor anchor = page.getAnchorByText(domain);
	assertNotNull(anchor);
	page = anchor.click();
	assertTrue(page.asText().contains("Beans in domain " + domain));

	anchor = page.getAnchorByName("text");
	TextPage textPage = anchor.click();
	String bean = "type=Memory";
	assertTrue(textPage.getContent().contains(domain + ":" + bean));

	anchor = page.getAnchorByText(bean);
	page = anchor.click();
	assertTrue(page.asText().contains("Information about object " + domain + ":" + bean));

	anchor = page.getAnchorByName("text");
	textPage = anchor.click();
	assertTrue(textPage.getContent().contains("Verbose"));

	HtmlForm form = page.getFormByName("Verbose");
	assertNotNull(form);
	HtmlInput input = form.getInputByName("val");
	assertEquals("false", input.getValueAttribute());
	assertNotNull(input);
	input.setValueAttribute("true");
	HtmlElement button = (HtmlElement) page.createElement("button");
	button.setAttribute("type", "submit");
	// append the button to the form to simulate
	form.appendChild(button);
	// submit the form
	page = button.click();
	assertTrue(page.asText().contains("Information about object " + domain + ":" + bean));

	form = page.getFormByName("Verbose");
	assertNotNull(form);
	input = form.getInputByName("val");
	assertEquals("true", input.getValueAttribute());

	String operation = "gc";
	form = page.getFormByName(operation);
	assertNotNull(form);
	input = form.getInputByValue(operation);
	page = input.click();

	assertTrue(page.asText().contains("Invoking Operation " + operation));
	assertTrue(page.asText().contains(operation + " method successfully invoked."));

	anchor = page.getAnchorByName("text");
	assertNotNull(anchor);
	textPage = anchor.click();
	assertEquals(operation + " method successfully invoked.\n", textPage.getContent());
}