/** * {@inheritDoc} */ @Override public boolean hasFocus() { return activeElement_ != null && getPage().getFocusedElement() == activeElement_.getDomNodeOrDie(); }
/** * {@inheritDoc} */ @Override public boolean hasFocus() { return activeElement_ != null && getPage().getFocusedElement() == activeElement_.getDomNodeOrDie(); }
/** * Simulate pressing an access key. This may change the focus, may click buttons and may invoke * JavaScript. * * @param accessKey the key that will be pressed * @return the element that has the focus after pressing this access key or null if no element * has the focus. * @throws IOException if an IO error occurs during the processing of this access key (this * would only happen if the access key triggered a button which in turn caused a page load) */ public DomElement pressAccessKey(final char accessKey) throws IOException { final HtmlElement element = getHtmlElementByAccessKey(accessKey); if (element != null) { element.focus(); if (element instanceof HtmlAnchor || element instanceof HtmlArea || element instanceof HtmlButton || element instanceof HtmlInput || element instanceof HtmlLabel || element instanceof HtmlLegend || element instanceof HtmlTextArea) { final Page newPage = element.click(); if (newPage != this && getFocusedElement() == element) { // The page was reloaded therefore no element on this page will have the focus. getFocusedElement().blur(); } } } return getFocusedElement(); }
/** * Simulate pressing an access key. This may change the focus, may click buttons and may invoke * JavaScript. * * @param accessKey the key that will be pressed * @return the element that has the focus after pressing this access key or null if no element * has the focus. * @throws IOException if an IO error occurs during the processing of this access key (this * would only happen if the access key triggered a button which in turn caused a page load) */ public DomElement pressAccessKey(final char accessKey) throws IOException { final HtmlElement element = getHtmlElementByAccessKey(accessKey); if (element != null) { element.focus(); if (element instanceof HtmlAnchor || element instanceof HtmlArea || element instanceof HtmlButton || element instanceof HtmlInput || element instanceof HtmlLabel || element instanceof HtmlLegend || element instanceof HtmlTextArea) { final Page newPage = element.click(); if (newPage != this && getFocusedElement() == element) { // The page was reloaded therefore no element on this page will have the focus. getFocusedElement().blur(); } } } return getFocusedElement(); }
/** * {@inheritDoc} */ @Override public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); // if value is changed and this element has the focus, then select the new value final Page page = getPage(); if (qualifiedName.equals("value") && page instanceof HtmlPage && ((HtmlPage) page).getFocusedElement() == this) { setSelectionStart(attributeValue.length()); setSelectionEnd(attributeValue.length()); } }
/** * {@inheritDoc} */ @Override public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); // if value is changed and this element has the focus, then select the new value final Page page = getPage(); if (qualifiedName.equals("value") && page instanceof HtmlPage && ((HtmlPage) page).getFocusedElement() == this) { setSelectionStart(attributeValue.length()); setSelectionEnd(attributeValue.length()); } }
/** * {@inheritDoc} */ @Override public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); // if value is changed and this element has the focus, then select the new value final Page page = getPage(); if (qualifiedName.equals("value") && page instanceof HtmlPage && ((HtmlPage) page).getFocusedElement() == this) { setSelectionStart(attributeValue.length()); setSelectionEnd(attributeValue.length()); } }
final DomElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(elements.size() - 1);
final HtmlElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(elements.size() - 1);
final HtmlElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(elements.size() - 1);
final DomElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(0);
final HtmlElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(elements.size() - 1);
final DomElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(elements.size() - 1);
final HtmlElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(0);
final HtmlElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(0);
final HtmlElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(0);
final DomElement elementWithFocus = getFocusedElement(); if (elementWithFocus == null) { elementToGiveFocus = elements.get(0);
public WebElement activeElement() { Page page = currentWindow.getEnclosedPage(); if (page instanceof HtmlPage) { HtmlElement element = ((HtmlPage) page).getFocusedElement(); if (element == null) { List<? extends HtmlElement> allBodies = ((HtmlPage) page).getDocumentElement().getHtmlElementsByTagName("body"); if (allBodies.size() > 0) { return newHtmlUnitWebElement(allBodies.get(0)); } } else { return newHtmlUnitWebElement(element); } } throw new NoSuchElementException("Unable to locate element with focus or body tag"); }
final Page enclosedPage = currentWindow_.getEnclosedPage(); if (enclosedPage != null && enclosedPage.isHtmlPage()) { final DomElement focusedElement = ((HtmlPage) enclosedPage).getFocusedElement(); if (focusedElement != null) { focusedElement.fireEvent(Event.TYPE_BLUR);
final Page enclosedPage = currentWindow_.getEnclosedPage(); if (enclosedPage != null && enclosedPage.isHtmlPage()) { final DomElement focusedElement = ((HtmlPage) enclosedPage).getFocusedElement(); if (focusedElement != null) { focusedElement.fireEvent(Event.TYPE_BLUR);