WebClient client = new WebClient(); HtmlPage page = client.getPage("http://stackoverflow.com"); // create a submit button - it doesn't work with 'input' HtmlElement button = page.createElement("button"); button.setAttribute("type", "submit"); // append the button to the form HtmlElement form = ...; form.appendChild(button); // submit the form page = button.click();
/** * {@inheritDoc} */ @Override public DomNode appendChild(final Node node) { final DomNode response = super.appendChild(node); if (node instanceof HtmlOption) { final HtmlOption option = (HtmlOption) node; if (option.isSelected()) { doSelectOption(option, true, false, false, false); } } return response; }
/** * {@inheritDoc} */ @Override public DomNode appendChild(final Node node) { final DomNode response = super.appendChild(node); if (node instanceof HtmlOption) { final HtmlOption option = (HtmlOption) node; if (option.isSelected()) { doSelectOption(option, true, false, false, false); } } return response; }
/** * Appends a child element to this HTML element with the specified tag name * if this HTML element does not already have a child with that tag name. * Returns the appended child element, or the first existent child element * with the specified tag name if none was appended. * @param tagName the tag name of the child to append * @return the added child, or the first existing child if none was added */ public final HtmlElement appendChildIfNoneExists(final String tagName) { final HtmlElement child; final List<HtmlElement> children = getElementsByTagName(tagName); if (children.isEmpty()) { // Add a new child and return it. child = (HtmlElement) ((HtmlPage) getPage()).createElement(tagName); appendChild(child); } else { // Return the first existing child. child = children.get(0); } return child; }
/** * Appends a child element to this HTML element with the specified tag name * if this HTML element does not already have a child with that tag name. * Returns the appended child element, or the first existent child element * with the specified tag name if none was appended. * @param tagName the tag name of the child to append * @return the added child, or the first existing child if none was added */ public final HtmlElement appendChildIfNoneExists(final String tagName) { final HtmlElement child; final List<HtmlElement> children = getHtmlElementsByTagName(tagName); if (children.isEmpty()) { // Add a new child and return it. child = ((HtmlPage) getPage()).createElement(tagName); appendChild(child); } else { // Return the first existing child. child = children.get(0); } return child; }
/** * Adds the new node to the right parent that is not necessary the currentNode in case * of malformed HTML code. */ private void addNodeToRightParent(final DomNode currentNode, final HtmlElement newElement) { final String currentNodeName = currentNode.getNodeName(); final String newNodeName = newElement.getNodeName(); // this only fixes bug http://sourceforge.net/support/tracker.php?aid=2767865 // TODO: understand in which cases it should be done to generalize it!!! if ("table".equals(currentNodeName) && "div".equals(newNodeName)) { currentNode.insertBefore(newElement); } else if ("title".equals(newNodeName) && head_ != null) { head_.appendChild(newElement); } else { currentNode.appendChild(newElement); } }
/** * Appends a child element to this HTML element with the specified tag name * if this HTML element does not already have a child with that tag name. * Returns the appended child element, or the first existent child element * with the specified tag name if none was appended. * @param tagName the tag name of the child to append * @return the added child, or the first existing child if none was added */ public final HtmlElement appendChildIfNoneExists(final String tagName) { final HtmlElement child; final List<HtmlElement> children = getHtmlElementsByTagName(tagName); if (children.isEmpty()) { // Add a new child and return it. child = ((HtmlPage) getPage()).createElement(tagName); appendChild(child); } else { // Return the first existing child. child = children.get(0); } return child; }
/** * Appends a child element to this HTML element with the specified tag name * if this HTML element does not already have a child with that tag name. * Returns the appended child element, or the first existent child element * with the specified tag name if none was appended. * @param tagName the tag name of the child to append * @return the added child, or the first existing child if none was added */ public final HtmlElement appendChildIfNoneExists(final String tagName) { final HtmlElement child; final List<HtmlElement> children = getHtmlElementsByTagName(tagName); if (children.isEmpty()) { // Add a new child and return it. child = ((HtmlPage) getPage()).createElement(tagName); appendChild(child); } else { // Return the first existing child. child = children.get(0); } return child; }
/** * Adds the new node to the right parent that is not necessary the currentNode in case * of malformed HTML code. */ private void addNodeToRightParent(final DomNode currentNode, final HtmlElement newElement) { final String currentNodeName = currentNode.getNodeName(); final String newNodeName = newElement.getNodeName(); // this only fixes bug http://sourceforge.net/support/tracker.php?aid=2767865 // TODO: understand in which cases it should be done to generalize it!!! if ("table".equals(currentNodeName) && "div".equals(newNodeName)) { currentNode.insertBefore(newElement); } else if ("title".equals(newNodeName) && head_ != null) { head_.appendChild(newElement); } else { currentNode.appendChild(newElement); } }
/** * Adds the new node to the right parent that is not necessary the currentNode in case * of malformed HTML code. */ private void addNodeToRightParent(final DomNode currentNode, final HtmlElement newElement) { final String currentNodeName = currentNode.getNodeName(); final String newNodeName = newElement.getNodeName(); // this only fixes bug http://sourceforge.net/support/tracker.php?aid=2767865 // TODO: understand in which cases it should be done to generalize it!!! if ("table".equals(currentNodeName) && "div".equals(newNodeName)) { currentNode.insertBefore(newElement); } else if ("title".equals(newNodeName) && head_ != null) { head_.appendChild(newElement); } else { currentNode.appendChild(newElement); } }
/** * Appends a child element to this HTML element with the specified tag name * if this HTML element does not already have a child with that tag name. * Returns the appended child element, or the first existent child element * with the specified tag name if none was appended. * @param tagName the tag name of the child to append * @return the added child, or the first existing child if none was added */ public final HtmlElement appendChildIfNoneExists(final String tagName) { final HtmlElement child; final List<HtmlElement> children = getElementsByTagName(tagName); if (children.isEmpty()) { // Add a new child and return it. child = (HtmlElement) ((HtmlPage) getPage()).createElement(tagName); appendChild(child); } else { // Return the first existing child. child = children.get(0); } return child; }
/** * Sets the tFoot. * @param o the tFoot */ @JsxSetter public void setTFoot(final Object o) { if (!(o instanceof HTMLTableSectionElement && "TFOOT".equals(((HTMLTableSectionElement) o).getTagName()))) { throw Context.reportRuntimeError("Not a tFoot"); } // remove old caption (if any) deleteTFoot(); final HTMLTableSectionElement tfoot = (HTMLTableSectionElement) o; getDomNodeOrDie().appendChild(tfoot.getDomNodeOrDie()); }
/** * Sets the {@code tHead}. * @param o the {@code tHead} */ @JsxSetter public void setTHead(final Object o) { if (!(o instanceof HTMLTableSectionElement && "THEAD".equals(((HTMLTableSectionElement) o).getTagName()))) { throw Context.reportRuntimeError("Not a tHead"); } // remove old caption (if any) deleteTHead(); final HTMLTableSectionElement thead = (HTMLTableSectionElement) o; getDomNodeOrDie().appendChild(thead.getDomNodeOrDie()); }
/** * Sets the tFoot. * @param o the tFoot */ @JsxSetter public void setTFoot(final Object o) { if (!(o instanceof HTMLTableSectionElement && "TFOOT".equals(((HTMLTableSectionElement) o).getTagName()))) { throw Context.reportRuntimeError("Not a tFoot"); } // remove old caption (if any) deleteTFoot(); final HTMLTableSectionElement tfoot = (HTMLTableSectionElement) o; getDomNodeOrDie().appendChild(tfoot.getDomNodeOrDie()); }
/** * Sets the caption. * @param o the caption */ @JsxSetter public void setCaption(final Object o) { if (!(o instanceof HTMLTableCaptionElement)) { throw Context.reportRuntimeError("Not a caption"); } // remove old caption (if any) deleteCaption(); final HTMLTableCaptionElement caption = (HTMLTableCaptionElement) o; getDomNodeOrDie().appendChild(caption.getDomNodeOrDie()); }
/** * Sets the {@code tHead}. * @param o the {@code tHead} */ @JsxSetter public void setTHead(final Object o) { if (!(o instanceof HTMLTableSectionElement && "THEAD".equals(((HTMLTableSectionElement) o).getTagName()))) { throw Context.reportRuntimeError("Not a tHead"); } // remove old caption (if any) deleteTHead(); final HTMLTableSectionElement thead = (HTMLTableSectionElement) o; getDomNodeOrDie().appendChild(thead.getDomNodeOrDie()); }
/** * Sets the caption. * @param o the caption */ @JsxSetter public void setCaption(final Object o) { if (!(o instanceof HTMLTableCaptionElement)) { throw Context.reportRuntimeError("Not a caption"); } // remove old caption (if any) deleteCaption(); final HTMLTableCaptionElement caption = (HTMLTableCaptionElement) o; getDomNodeOrDie().appendChild(caption.getDomNodeOrDie()); }
/** * Sets the {@code text} property. * @param text the {@code text} property */ @JsxSetter public void setText(final String text) { final HtmlElement htmlElement = getDomNodeOrDie(); htmlElement.removeAllChildren(); final DomNode textChild = new DomText(htmlElement.getPage(), text); htmlElement.appendChild(textChild); final HtmlScript tmpScript = (HtmlScript) htmlElement; tmpScript.executeScriptIfNeeded(); }
/** * Sets the {@code text} property. * @param text the {@code text} property */ @JsxSetter public void setText(final String text) { final HtmlElement htmlElement = getDomNodeOrDie(); htmlElement.removeAllChildren(); final DomNode textChild = new DomText(htmlElement.getPage(), text); htmlElement.appendChild(textChild); final HtmlScript tmpScript = (HtmlScript) htmlElement; tmpScript.executeScriptIfNeeded(); }
/** * Returns the node to type into. * @return the node */ private DomNode getDoTypeNode() { DomNode node = null; final HTMLElement scriptElement = getScriptableObject(); if (scriptElement.isIsContentEditable() || "on".equals(((Document) scriptElement.getOwnerDocument()).getDesignMode())) { final DomNodeList<DomNode> children = getChildNodes(); if (!children.isEmpty()) { final DomNode lastChild = children.get(children.size() - 1); if (lastChild instanceof DomText) { node = lastChild; } else if (lastChild instanceof HtmlElement) { node = lastChild; } } if (node == null) { final DomText domText = new DomText(getPage(), ""); appendChild(domText); node = domText; } } return node; }