Sets the focus on this element.
()
| 1571 | * Sets the focus on this element. |
| 1572 | */ |
| 1573 | public void focus() { |
| 1574 | if (!(this instanceof SubmittableElement |
| 1575 | || this instanceof HtmlAnchor anchor && ATTRIBUTE_NOT_DEFINED != anchor.getHrefAttribute() |
| 1576 | || this instanceof HtmlArea area |
| 1577 | && (ATTRIBUTE_NOT_DEFINED != area.getHrefAttribute() |
| 1578 | || getPage().getWebClient().getBrowserVersion().hasFeature(JS_AREA_WITHOUT_HREF_FOCUSABLE)) |
| 1579 | || this instanceof HtmlElement && ((HtmlElement) this).getTabIndex() != null)) { |
| 1580 | return; |
| 1581 | } |
| 1582 | |
| 1583 | if (!isDisplayed() || isDisabledElementAndDisabled()) { |
| 1584 | return; |
| 1585 | } |
| 1586 | |
| 1587 | final HtmlPage page = (HtmlPage) getPage(); |
| 1588 | page.setFocusedElement(this); |
| 1589 | } |
| 1590 | |
| 1591 | /** |
| 1592 | * Removes focus from this element. |
no test coverage detected