Bug 1420431 - Return no such element error when on no active element. r=maja_zf

document.activeElement will return null if there is no document
element.  This may happen if, for example, in an HTML document the
<body> element is removed.

The WPT test test_sucess_without_body in get_active_element.py
is wrong.  It expects Get Active Element to return null if there
is no document element, but following a recent specification change
we want it to return a no such element error.

Specification change: https://github.com/w3c/webdriver/pull/1157

MozReview-Commit-ID: LQJ3slV9aty

--HG--
extra : rebase_source : cc349bb642f57bb2203d126ecd86d8d988d90301
This commit is contained in:
Andreas Tolfsen 2017-11-24 16:23:02 +00:00
parent 4ee38f4584
commit 4a2fe54072
5 changed files with 26 additions and 10 deletions

View File

@ -2159,10 +2159,11 @@ GeckoDriver.prototype.findElements = async function(cmd, resp) {
};
/**
* Return the active element on the page.
* Return the active element in the document.
*
* @return {WebElement}
* Active element of the current browsing context's document element.
* Active element of the current browsing context's document
* element, if the document element is non-null.
*
* @throws {UnsupportedOperationError}
* Not available in current context.
@ -2170,6 +2171,9 @@ GeckoDriver.prototype.findElements = async function(cmd, resp) {
* Top-level browsing context has been discarded.
* @throws {UnexpectedAlertOpenError}
* A modal dialog is open, blocking this operation.
* @throws {NoSuchElementError}
* If the document does not have an active element, i.e. if
* its document element has been deleted.
*/
GeckoDriver.prototype.getActiveElement = async function() {
assert.content(this.context);

View File

@ -1274,9 +1274,22 @@ async function findElementsContent(strategy, selector, opts = {}) {
return webEls;
}
/** Find and return the active element on the page. */
/**
* Return the active element in the document.
*
* @return {WebElement}
* Active element of the current browsing context's document
* element, if the document element is non-null.
*
* @throws {NoSuchElementError}
* If the document does not have an active element, i.e. if
* its document element has been deleted.
*/
function getActiveElement() {
let el = curContainer.frame.document.activeElement;
if (!el) {
throw new NoSuchElementError();
}
return evaluate.toJSON(el, seenEls);
}

View File

@ -575993,7 +575993,7 @@
"wdspec"
],
"webdriver/tests/element_retrieval/get_active_element.py": [
"74bb0beec41ab857f6814d47191f29065a536802",
"918c6e48047f31a088ec44e9b0d070b0ae3d6077",
"wdspec"
],
"webdriver/tests/fullscreen_window.py": [

View File

@ -1,11 +1,8 @@
[get_active_element.py]
type: wdspec
[get_active_element.py::test_handle_prompt_dismiss]
expected: FAIL
[get_active_element.py::test_handle_prompt_accept]
expected: FAIL
[get_active_element.py::test_sucess_without_body]
expected: FAIL

View File

@ -2,9 +2,11 @@ from tests.support.asserts import assert_error, assert_dialog_handled, assert_sa
from tests.support.fixtures import create_dialog
from tests.support.inline import inline
def read_global(session, name):
return session.execute_script("return %s;" % name)
def get_active_element(session):
return session.transport.send("GET", "session/%s/element/active" % session.session_id)
@ -244,7 +246,7 @@ def test_success_iframe_content(session):
assert_is_active_element(session, response)
def test_sucess_without_body(session):
def test_missing_document_element(session):
session.url = inline("<body></body>")
session.execute_script("""
if (document.body.remove) {
@ -254,4 +256,4 @@ def test_sucess_without_body(session):
}""")
response = get_active_element(session)
assert_is_active_element(session, response)
assert_error(response, "no such element")