Java Code Examples for com.gargoylesoftware.htmlunit.html.DomElement#click()

The following examples show how to use com.gargoylesoftware.htmlunit.html.DomElement#click() . 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: EventTarget.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Dispatches an event into the event system (standards-conformant browsers only). See
 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent">the Gecko
 * DOM reference</a> for more information.
 *
 * @param event the event to be dispatched
 * @return {@code false} if at least one of the event handlers which handled the event
 *         called <tt>preventDefault</tt>; {@code true} otherwise
 */
@JsxFunction
public boolean dispatchEvent(final Event event) {
    event.setTarget(this);
    final DomElement element = (DomElement) getDomNodeOrNull();
    ScriptResult result = null;
    if (event.getType().equals(MouseEvent.TYPE_CLICK)) {
        try {
            element.click(event, event.isShiftKey(), event.isCtrlKey(), event.isAltKey(), true);
        }
        catch (final IOException e) {
            throw Context.reportRuntimeError("Error calling click(): " + e.getMessage());
        }
    }
    else {
        result = fireEvent(event);
    }
    return !event.isAborted(result);
}
 
Example 2
Source File: EventTarget.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Dispatches an event into the event system (standards-conformant browsers only). See
 * <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent">the Gecko
 * DOM reference</a> for more information.
 *
 * @param event the event to be dispatched
 * @return {@code false} if at least one of the event handlers which handled the event
 *         called <tt>preventDefault</tt>; {@code true} otherwise
 */
@JsxFunction
public boolean dispatchEvent(final Event event) {
    event.setTarget(this);
    final DomElement element = (DomElement) getDomNodeOrNull();
    ScriptResult result = null;
    if (event.getType().equals(MouseEvent.TYPE_CLICK)) {
        try {
            element.click(event, true);
        }
        catch (final IOException e) {
            throw Context.reportRuntimeError("Error calling click(): " + e.getMessage());
        }
    }
    else {
        result = fireEvent(event);
    }
    return !event.isAborted(result);
}
 
Example 3
Source File: PageObject.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
static HtmlPage clickOnElement(final DomElement element) {
    try {
        return element.click();
    }
    catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example 4
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Clicks the specified DOM element and returns the HTML page content of the page that is the target of the link.
 *
 * @param element
 *         the element that receives the click event
 *
 * @return the HTML page
 */
protected HtmlPage clickOnLink(final DomElement element) {
    try {
        return element.click();
    }
    catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example 5
Source File: HtmlUnitTests.java    From demo with MIT License 5 votes vote down vote up
private HtmlPage click(DomElement button) {
    try {
        return button.click();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}