Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Bug 1420431 - Return no such element error when on no active element.…
Browse files Browse the repository at this point in the history
… 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: w3c/webdriver#1157

MozReview-Commit-ID: LQJ3slV9aty
  • Loading branch information
andreastt committed Nov 24, 2017
1 parent 698252c commit 44ce915
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
8 changes: 6 additions & 2 deletions testing/marionette/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2159,17 +2159,21 @@ 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.
* @throws {NoSuchWindowError}
* 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);
Expand Down
15 changes: 14 additions & 1 deletion testing/marionette/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion testing/web-platform/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -575993,7 +575993,7 @@
"wdspec"
],
"webdriver/tests/element_retrieval/get_active_element.py": [
"74bb0beec41ab857f6814d47191f29065a536802",
"918c6e48047f31a088ec44e9b0d070b0ae3d6077",
"wdspec"
],
"webdriver/tests/fullscreen_window.py": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
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)

Expand Down Expand Up @@ -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) {
Expand All @@ -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")

0 comments on commit 44ce915

Please sign in to comment.