This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26158 - JSON serialization of element does not make clear that JSON represents an element
Summary: JSON serialization of element does not make clear that JSON represents an ele...
Status: RESOLVED FIXED
Alias: None
Product: Browser Test/Tools WG
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Browser Testing and Tools WG
QA Contact: Browser Testing and Tools WG
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 20860
  Show dependency treegraph
 
Reported: 2014-06-20 20:28 UTC by Jim Evans
Modified: 2014-07-28 21:53 UTC (History)
2 users (show)

See Also:


Attachments

Description Jim Evans 2014-06-20 20:28:44 UTC
Section 9.1 states that the WebElement interface has an attribute named "id". Thus, when serialized, a reference to an element when returned from a JavaScript execution would look like this:

{"id": "<element id>"}

Now consider returning a JavaScript object literal with the following JSON definition:

{"id": "this is my super ID value"}

It will be impossible to distinguish between a legitimate WebElement reference, and an object literal when evaluating the returned JSON value. The Selenium open-source project mitigates this by using a property name of "ELEMENT" instead of "id" for element references. Using "id" is problematic, merely because there are any number of uses for returning an object with an "id" property. Renaming the property to something like "webdriverElementId" would likely resolve the issue.
Comment 1 Jim Evans 2014-06-20 20:30:56 UTC
Adding an additional concrete example using Java from the existing OSS project language bindings:

JavascriptExecutor executor = (JavascriptExecutor)driver;
 
// Can value1 be cast to a WebElement in the Java bindings?
// It should be able to, because that's what it represents.
Object value1 = executor.executeScript("return document.getElementById('foo');");
 
// value2 should be castable to a Map<String, Object>, because
// we're returning an object literal, but how can the language
// binding know that the result *isn't* a WebElement. There's
// no way to tell the difference by looking only at the serialized
// JSON response.
Object value2 = executor.executeScript("return { \"id\": \"this is my fake element id\" };");
Comment 2 David Burns :automatedtester 2014-07-28 16:43:41 UTC
This will be updated as http://www.w3.org/2014/07/07-testing-minutes.html#action25
Comment 3 David Burns :automatedtester 2014-07-28 21:53:46 UTC
https://dvcs.w3.org/hg/webdriver/rev/d81488ae4045

I did not update section 14 with this patch as that section is currently being rewritten after f2f in London