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

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlPasswordInput. 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: demo   Source File: HtmlUnitTests.java    License: MIT License 6 votes vote down vote up
private void type(DomElement input, String text) {
    try {
        // try to send text assuming it's a text input...
        ((HtmlTextInput) input).type(text);
    } catch (Exception ex) {
        // if we fail *because* it's a password input
        if (ex.getMessage().contains("HtmlPasswordInput cannot be cast to class com.gargoylesoftware.htmlunit.html.HtmlTextInput")) {
            try {
                // try to use it as a password input.
                ((HtmlPasswordInput) input).type(text);
            } catch (Exception ex1) {
                throw new RuntimeException(ex1);
            }
        }
    }
}