driver.switchTo().activeElement()
will return the currently focused WebElement
. Equality is well defined for WebElement
, so you can call element.equals(driver.switchTo().activeElement())
.
Calling the slightly misleading named driver.switchTo().activeElement()
does not in fact switch focus, neither does driver.findElement()
, so you do not need to switchTo().defaultContent()
after; in fact, doing so would probably blur the current element.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…