Bug 1411281 - Swap webdriver.Element ctor arguments
It is more natural for the web element UUID to come first, followed
by the associated session state.
The patch also adds ctor documentation.
MozReview-Commit-ID: 5iV4SZzMeKS
--- a/testing/web-platform/tests/tools/webdriver/webdriver/client.py
+++ b/testing/web-platform/tests/tools/webdriver/webdriver/client.py
@@ -543,17 +543,17 @@ class Session(object):
if data is not None:
return self._element(data)
def _element(self, data):
elem_id = data[Element.identifier]
assert elem_id
if elem_id in self._element_cache:
return self._element_cache[elem_id]
- return Element(self, elem_id)
+ return Element(elem_id, self)
@command
def cookies(self, name=None):
if name is None:
url = "cookie"
else:
url = "cookie/%s" % name
return self.send_session_command("GET", url, {})
@@ -614,19 +614,27 @@ class Element(object):
"""
Representation of a web element.
A web element is an abstraction used to identify an element when
it is transported via the protocol, between remote- and local ends.
"""
identifier = "element-6066-11e4-a52e-4f735466cecf"
- def __init__(self, session, id):
+ def __init__(self, id, session):
+ """
+ Construct a new web element representation.
+
+ :param id: Web element UUID which must be unique across
+ all browsing contexts.
+ :param session: Current ``webdriver.Session``.
+ """
+ self.id = id
self.session = session
- self.id = id
+
assert id not in self.session._element_cache
self.session._element_cache[self.id] = self
def __eq__(self, other):
return isinstance(other, Element) and self.id == other.id \
and self.session == other.session
def send_element_command(self, method, uri, body=None):