/** * Removes focus from this element. */ public void blur() { ((HtmlPage) getPage()).setFocusedElement(null); }
/** * Removes focus from this element. */ public void blur() { ((HtmlPage) getPage()).setFocusedElement(null); }
/** * @param node a node * @return the xml representation according to the setting of this serializer * @throws IOException in case of problem saving resources */ public String asXml(final DomElement node) throws IOException { builder_.setLength(0); indent_.setLength(0); final SgmlPage page = node.getPage(); if (null != page && page.isHtmlPage()) { final Charset charsetName = page.getCharset(); if (charsetName != null && node instanceof HtmlHtml) { builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } } printXml(node); final String response = builder_.toString(); builder_.setLength(0); return response; }
/** * Simulates right clicking the mouse on this element, returning the page which this element's window * contains after the mouse click. The returned page may or may not be the same as the original page, * depending on JavaScript event handlers, etc. * * @param shiftKey {@code true} if SHIFT is pressed during the mouse click * @param ctrlKey {@code true} if CTRL is pressed during the mouse click * @param altKey {@code true} if ALT is pressed during the mouse click * @return the page which this element's window contains after the mouse click */ public Page rightClick(final boolean shiftKey, final boolean ctrlKey, final boolean altKey) { final Page mouseDownPage = mouseDown(shiftKey, ctrlKey, altKey, MouseEvent.BUTTON_RIGHT); if (mouseDownPage != getPage()) { if (LOG.isDebugEnabled()) { LOG.debug("rightClick() is incomplete, as mouseDown() loaded a different page."); } return mouseDownPage; } final Page mouseUpPage = mouseUp(shiftKey, ctrlKey, altKey, MouseEvent.BUTTON_RIGHT); if (mouseUpPage != getPage()) { if (LOG.isDebugEnabled()) { LOG.debug("rightClick() is incomplete, as mouseUp() loaded a different page."); } return mouseUpPage; } return doMouseEvent(MouseEvent.TYPE_CONTEXT_MENU, shiftKey, ctrlKey, altKey, MouseEvent.BUTTON_RIGHT); }
/** * @param node a node * @return the xml representation according to the setting of this serializer * @throws IOException in case of problem saving resources */ public String asXml(final DomElement node) throws IOException { builder_.setLength(0); indent_.setLength(0); final SgmlPage page = node.getPage(); if (null != page && page.isHtmlPage()) { final Charset charsetName = page.getCharset(); if (charsetName != null && node instanceof HtmlHtml) { builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n'); } } printXml(node); final String response = builder_.toString(); builder_.setLength(0); return response; }
/** * Sets the focus on this element. */ public void focus() { final HtmlPage page = (HtmlPage) getPage(); page.setFocusedElement(this); final Object o = getScriptableObject(); if (o instanceof HTMLElement) { ((HTMLElement) o).setActive(); } }
/** * Sets the focus on this element. */ public void focus() { final HtmlPage page = (HtmlPage) getPage(); page.setFocusedElement(this); final Object o = getScriptableObject(); if (o instanceof HTMLElement) { ((HTMLElement) o).setActive(); } }
private void updateAttribute(final String value) { final DomElement domNode = (DomElement) getDomNodeOrDie(); DomAttr attr = (DomAttr) domNode.getAttributes().getNamedItem(attributeName_); if (null == attr) { attr = domNode.getPage().createAttribute(attributeName_); domNode.setAttributeNode(attr); } attr.setValue(value); }
private void updateAttribute(final String value) { final DomElement domNode = (DomElement) getDomNodeOrDie(); DomAttr attr = (DomAttr) domNode.getAttributes().getNamedItem(attributeName_); if (null == attr) { attr = domNode.getPage().createAttribute(attributeName_); domNode.setAttributeNode(attr); } attr.setValue(value); }
protected void assertElementNotStale(DomElement element) { SgmlPage elementPage = element.getPage(); Page currentPage = lastPage(); if (!currentPage.equals(elementPage)) { throw new StaleElementReferenceException( "Element appears to be stale. Did you navigate away from the page that contained it? " + " And is the current window focussed the same as the one holding this element?"); } // We need to walk the DOM to determine if the element is actually attached DomNode parentElement = element; while (parentElement != null && !(parentElement instanceof SgmlPage)) { parentElement = parentElement.getParentNode(); } if (parentElement == null) { throw new StaleElementReferenceException( "The element seems to be disconnected from the DOM. " + " This means that a user cannot interact with it."); } }
private Map<String, DomAttr> readAttributes(final DomElement node) throws IOException { if (node instanceof HtmlImage) { return getAttributesFor((HtmlImage) node); } else if (node instanceof HtmlLink) { return getAttributesFor((HtmlLink) node); } else if (node instanceof BaseFrameElement) { return getAttributesFor((BaseFrameElement) node); } Map<String, DomAttr> attributes = node.getAttributesMap(); if (node instanceof HtmlOption) { attributes = new HashMap<>(attributes); final HtmlOption option = (HtmlOption) node; if (option.isSelected()) { if (!attributes.containsKey("selected")) { attributes.put("selected", new DomAttr(node.getPage(), null, "selected", "selected", false)); } } else { attributes.remove("selected"); } } return attributes; }
/** * Sets the value of the attribute specified by namespace and qualified name. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name (prefix:local) of the attribute * @param attributeValue the value of the attribute * @param notifyAttributeChangeListeners to notify the associated {@link HtmlAttributeChangeListener}s * @param notifyMutationObservers to notify {@code MutationObserver}s or not */ protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) { final String value = attributeValue; final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value, true); newAttr.setParentNode(this); attributes_.put(qualifiedName, newAttr); if (namespaceURI != null) { namespaces_.put(namespaceURI, newAttr.getPrefix()); } }
/** * Sets the value of the attribute specified by namespace and qualified name. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name (prefix:local) of the attribute * @param attributeValue the value of the attribute * @param notifyAttributeChangeListeners to notify the associated {@link HtmlAttributeChangeListener}s * @param notifyMutationObservers to notify {@code MutationObserver}s or not */ protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) { final String value = attributeValue; final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value, true); newAttr.setParentNode(this); attributes_.put(qualifiedName, newAttr); if (namespaceURI != null) { namespaces_.put(namespaceURI, newAttr.getPrefix()); } }
/** * Returns true if the element would be selected by the specified selector string; otherwise, returns false. * @param selectorString the selector to test * @return true if the element would be selected by the specified selector string; otherwise, returns false. */ public boolean matches(final String selectorString) { try { final BrowserVersion browserVersion = getPage().getWebClient().getBrowserVersion(); final SelectorList selectorList = getSelectorList(selectorString, browserVersion); if (selectorList != null) { for (Selector selector : selectorList) { if (CSSStyleSheet.selects(browserVersion, selector, this, null, true)) { return true; } } } return false; } catch (final IOException e) { throw new CSSException("Error parsing CSS selectors from '" + selectorString + "': " + e.getMessage()); } } }
/** * Sets the value of the attribute specified by namespace and qualified name. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name (prefix:local) of the attribute * @param attributeValue the value of the attribute */ public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { final String value = attributeValue; if (attributes_ == NamedAttrNodeMapImpl.EMPTY_MAP) { attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive()); } final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value); newAttr.setParentNode(this); attributes_.put(qualifiedName, newAttr); if (namespaceURI != null) { namespaces().put(namespaceURI, newAttr.getPrefix()); } }
/** * Sets the value of the attribute specified by namespace and qualified name. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name (prefix:local) of the attribute * @param attributeValue the value of the attribute */ public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { final String value = attributeValue; if (attributes_ == NamedAttrNodeMapImpl.EMPTY_MAP) { attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive()); } final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value); newAttr.setParentNode(this); attributes_.put(qualifiedName, newAttr); if (namespaceURI != null) { namespaces().put(namespaceURI, newAttr.getPrefix()); } }
/** * Sets the value of the attribute specified by namespace and qualified name. * * @param namespaceURI the URI that identifies an XML namespace * @param qualifiedName the qualified name (prefix:local) of the attribute * @param attributeValue the value of the attribute */ public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { final String value = attributeValue; if (attributes_ == NamedAttrNodeMapImpl.EMPTY_MAP) { attributes_ = new NamedAttrNodeMapImpl(this, isAttributeCaseSensitive()); } final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value); newAttr.setParentNode(this); attributes_.put(qualifiedName, newAttr); if (namespaceURI != null) { namespaces().put(namespaceURI, newAttr.getPrefix()); } }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * Fires the event on the element. Nothing is done if JavaScript is disabled. * @param event the event to fire * @return the execution result, or {@code null} if nothing is executed */ public ScriptResult fireEvent(final Event event) { final WebClient client = getPage().getWebClient(); if (!client.getOptions().isJavaScriptEnabled()) { return null; } if (!handles(event)) { return null; } if (LOG.isDebugEnabled()) { LOG.debug("Firing " + event); } final EventTarget jsElt = getScriptableObject(); final ContextFactory cf = ((JavaScriptEngine) client.getJavaScriptEngine()).getContextFactory(); final ScriptResult result = (ScriptResult) cf.call(cx -> jsElt.fireEvent(event)); if (event.isAborted(result)) { preventDefault(); } return result; }
@Override public void execute() { final HTMLDocument jsDoc = (HTMLDocument) ((Window) element.getPage().getEnclosingWindow().getScriptableObject()).getDocument(); jsDoc.setExecutingDynamicExternalPosponed(element.getStartLineNumber() == -1 && ((ScriptElement) element).getSrcAttribute() != ATTRIBUTE_NOT_DEFINED); try { executeScriptIfNeeded(element); } finally { jsDoc.setExecutingDynamicExternalPosponed(false); } } };
@Override public void execute() { final HTMLDocument jsDoc = (HTMLDocument) ((Window) element.getPage().getEnclosingWindow().getScriptableObject()).getDocument(); jsDoc.setExecutingDynamicExternalPosponed(element.getStartLineNumber() == -1 && ((ScriptElement) element).getSrcAttribute() != ATTRIBUTE_NOT_DEFINED); try { executeScriptIfNeeded(element); } finally { jsDoc.setExecutingDynamicExternalPosponed(false); } } };