com.gargoylesoftware.htmlunit.PromptHandler Java Examples

The following examples show how to use com.gargoylesoftware.htmlunit.PromptHandler. 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
/**
 * The JavaScript function {@code prompt}.
 * @param message the message
 * @param defaultValue the default value displayed in the text input field
 * @return the value typed in or {@code null} if the user pressed {@code cancel}
 */
@JsxFunction
public String prompt(final String message, Object defaultValue) {
    final PromptHandler handler = getWebWindow().getWebClient().getPromptHandler();
    if (handler == null) {
        if (LOG.isWarnEnabled()) {
            LOG.warn("window.prompt(\"" + message + "\") no prompt handler installed");
        }
        return null;
    }
    if (Undefined.isUndefined(defaultValue)) {
        defaultValue = null;
    }
    else {
        defaultValue = Context.toString(defaultValue);
    }
    return handler.handlePrompt(document_.getPage(), message, (String) defaultValue);
}
 
Example #2
Source File: Window.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * The JavaScript function {@code prompt}.
 * @param message the message
 * @param defaultValue the default value displayed in the text input field
 * @return the value typed in or {@code null} if the user pressed {@code cancel}
 */
@JsxFunction
public String prompt(final String message, Object defaultValue) {
    final PromptHandler handler = getWebWindow().getWebClient().getPromptHandler();
    if (handler == null) {
        LOG.warn("window.prompt(\"" + message + "\") no prompt handler installed");
        return null;
    }
    if (defaultValue == Undefined.instance) {
        defaultValue = null;
    }
    else {
        defaultValue = Context.toString(defaultValue);
    }
    return handler.handlePrompt(document_.getPage(), message, (String) defaultValue);
}
 
Example #3
Source File: HiddenHtmlPrompt.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
@Override
@PublicAtsApi
public void clickOk(
                     final String promptValue ) {

    isProcessed = false;
    webClient.setPromptHandler(new PromptHandler() {

        @Override
        public String handlePrompt(
                                    Page currentPage,
                                    String promptText,
                                    String defaultValue ) {

            isProcessed = true;
            return promptValue;
        }
    });
}
 
Example #4
Source File: HiddenHtmlPrompt.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
@Override
@PublicAtsApi
public void clickOk(
                     final String expectedText,
                     final String promptValue ) {

    isProcessed = false;
    webClient.setPromptHandler(new PromptHandler() {

        @Override
        public String handlePrompt(
                                    Page currentPage,
                                    String promptText,
                                    String defaultValue ) {

            isProcessed = true;
            if (!promptText.equals(expectedText)) {

                throw new VerificationException("The expected prompt text was: '" + expectedText
                                                + "', but actually it is: '" + promptText + "'");
            }
            return promptValue;
        }
    });
}
 
Example #5
Source File: HiddenHtmlPrompt.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
@Override
@PublicAtsApi
public void clickCancel() {

    isProcessed = false;
    webClient.setPromptHandler(new PromptHandler() {

        @Override
        public String handlePrompt(
                                    Page currentPage,
                                    String promptText,
                                    String defaultValue ) {

            isProcessed = true;
            return null;
        }
    });
}
 
Example #6
Source File: HiddenHtmlPrompt.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
@Override
@PublicAtsApi
public void clickCancel(
                         final String expectedText ) {

    isProcessed = false;
    webClient.setPromptHandler(new PromptHandler() {

        @Override
        public String handlePrompt(
                                    Page currentPage,
                                    String promptText,
                                    String defaultValue ) {

            isProcessed = true;
            if (!promptText.equals(expectedText)) {

                throw new VerificationException("The expected prompt text was: '" + expectedText
                                                + "', but actually it is: '" + promptText + "'");
            }
            return null;
        }
    });
}