Bug 1409036 - Return single anon element from WebDriver:FindElement. r=whimboo

The WebDriver:FindElement command returned an array of elements when
looking up anonymous elements.  This patch rectifies the behaviour
so that only a single element is returned.

It introduces a new helper function called element.findAnonymousNodes,
akin to similar helper functions for other strategies.  This function
returns an iterator of anonymous nodes so that WebDriver:FindElements
(plural) and WebDriver:FindElement (singular) can share the same
code path.

MozReview-Commit-ID: 3IqPyAIZHtf

--HG--
extra : rebase_source : ceffd2b3dfe885b98ae31905f290ab9d95ef26c0
This commit is contained in:
Andreas Tolfsen 2017-10-05 12:59:03 +01:00
parent 4715a53b38
commit 2207b79606

View File

@ -412,6 +412,24 @@ element.findByLinkText = function(node, s) {
return filterLinks(node, link => link.text.trim() === s);
};
/**
* Find anonymous nodes of <var>node</var>.
*
* @param {XULElement} rootNode
* Root node of the document.
* @param {XULElement} node
* Where in the DOM hierarchy to begin searching.
*
* @return {Iterable.<XULElement>}
* Iterator over anonymous elements.
*/
element.findAnonymousNodes = function* (rootNode, node) {
let anons = rootNode.getAnonymousNodes(node) || [];
for (let node of anons) {
yield node;
}
};
/**
* Find all hyperlinks descendant of |node| which link text contains |s|.
*
@ -524,7 +542,7 @@ function findElement(using, value, rootNode, startNode) {
}
case element.Strategy.Anon:
return rootNode.getAnonymousNodes(startNode);
return element.findAnonymousNodes(rootNode, startNode).next().value;
case element.Strategy.AnonAttribute:
let attr = Object.keys(value)[0];
@ -587,7 +605,7 @@ function findElements(using, value, rootNode, startNode) {
return startNode.querySelectorAll(value);
case element.Strategy.Anon:
return rootNode.getAnonymousNodes(startNode);
return [...element.findAnonymousNodes(rootNode, startNode)];
case element.Strategy.AnonAttribute:
let attr = Object.keys(value)[0];