类com.gargoylesoftware.htmlunit.html.HtmlFileInput源码实例Demo

下面列出了怎么用com.gargoylesoftware.htmlunit.html.HtmlFileInput的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: htmlunit   文件: HTMLInputElement.java
/**
 * Returns the value of the JavaScript attribute {@code value}.
 *
 * @return the value of this attribute
 */
@JsxGetter
@Override
public String getValue() {
    final HtmlInput htmlInput = getDomNodeOrDie();
    if (htmlInput instanceof HtmlFileInput) {
        final File[] files = ((HtmlFileInput) htmlInput).getFiles();
        if (files == null || files.length == 0) {
            return ATTRIBUTE_NOT_DEFINED;
        }
        final File first = files[0];
        final String name = first.getName();
        if (name.isEmpty()) {
            return name;
        }
        return "C:\\fakepath\\" + name;
    }
    return htmlInput.getAttributeDirect("value");
}
 
源代码2 项目: htmlunit   文件: HTMLFormElement2Test.java
/**
 * @throws Exception if the test fails
 */
@Test
@Alerts("onchange")
public void fileInput_fireOnChange() throws Exception {
    final String html = "<html><body>\n"
        + "<form>\n"
        + "  <input type='file' name='myFile' id='myFile' onchange='alert(\"onchange\")'/>\n"
        + "</form>\n"
        + "</body></html>";

    final List<String> collectedAlerts = new ArrayList<>();
    final HtmlPage page = loadPage(html, collectedAlerts);
    final HtmlFileInput fileInput = page.getHtmlElementById("myFile");
    fileInput.focus();
    fileInput.setAttribute("value", "dummy.txt");
    assertEquals(getExpectedAlerts(), collectedAlerts);
}
 
源代码3 项目: HtmlUnit-Android   文件: HTMLInputElement.java
/**
 * {@inheritDoc}
 */
@Override
public String getValue() {
    final HtmlInput htmlInput = getDomNodeOrDie();
    if (htmlInput instanceof HtmlFileInput) {
        final File[] files = ((HtmlFileInput) getDomNodeOrDie()).getFiles();
        if (files == null || files.length == 0) {
            return ATTRIBUTE_NOT_DEFINED;
        }
        final File first = files[0];
        final String name = first.getName();
        if (name.isEmpty()) {
            return name;
        }
        if (getBrowserVersion().hasFeature(HTMLINPUT_FILE_VALUE_FAKEPATH)) {
            return "C:\\fakepath\\" + name;
        }
        return name;
    }
    return super.getValue();
}
 
源代码4 项目: htmlunit   文件: HTMLInputElement.java
/**
 * Returns the {@code files} property.
 * @return the {@code files} property
 */
@JsxGetter
public Object getFiles() {
    final HtmlInput htmlInput = getDomNodeOrDie();
    if (htmlInput instanceof HtmlFileInput) {
        final FileList list = new FileList(((HtmlFileInput) htmlInput).getFiles());
        list.setParentScope(getParentScope());
        list.setPrototype(getPrototype(list.getClass()));
        return list;
    }
    if (getBrowserVersion().hasFeature(HTMLINPUT_FILES_UNDEFINED)) {
        return Undefined.instance;
    }
    return null;
}
 
源代码5 项目: HtmlUnit-Android   文件: HTMLInputElement.java
/**
 * Returns the {@code files} property.
 * @return the {@code files} property
 */
@JsxGetter
public Object getFiles() {
    final HtmlInput htmlInput = getDomNodeOrDie();
    if (htmlInput instanceof HtmlFileInput) {
        final FileList list = new FileList(((HtmlFileInput) htmlInput).getFiles());
        list.setParentScope(getParentScope());
        list.setPrototype(getPrototype(list.getClass()));
        return list;
    }
    if (getBrowserVersion().hasFeature(HTMLINPUT_FILES_UNDEFINED)) {
        return Undefined.instance;
    }
    return null;
}
 
 类方法
 同包方法