public Field field(String field) { HtmlInput input = form.getInputByNameOrId(field); if (input != null) { if (logger.isDebugEnabled()) { logger.debug("Field is an input: " + input); } return new HtmlUnitField(this, input); } HtmlTextArea textArea = form.getTextAreaByNameOrId(field); if (textArea != null) { if (logger.isDebugEnabled()) { logger.debug("Field is a textarea: " + input); } return new HtmlUnitTextArea(this, textArea); } if (logger.isDebugEnabled()) { logger.debug("Trying to find a generic input"); } HtmlElement element = form.getElementByIdOrDie(field); if (element instanceof HtmlTextArea) { return new HtmlUnitTextArea(this, (HtmlTextArea) element); } return new HtmlUnitField(this, (HtmlInput) element); }
public void navigate(String element) { ClickableElement button = form.getInputByName(element); if (button == null) { if (logger.isDebugEnabled()) { logger.debug("Element " + element + " was not found by name, trying id"); } button = form.getElementByIdOrDie(element); } try { parent.setPage((HtmlPage) button.click()); } catch (IOException e) { throw new IllegalStateException(e); } }