[š Bug]: Incorrect description on JavascriptExecutor.executeScript
See original GitHub issueWhat happened?
Original description on Selenium Doc is as below
For a map, return a Map<String, Object> with values following the rules above.
As I thought, the word āmapā should be more common to avoid misunderstanding, e.g. object.
If this āmapā is only cover the Java Map, itās fine, below code will return a Map
((JavascriptExecutor) driver).executeScript("return arguments[0]", map)
But no other steps can cover common Object in Java, so it will go to
For all other cases, a String is returned
If this map is standing as JavaScript Map, whatās the expected response from WebDriver?
Try to call the WebDriver as below:
{ "script": "return new Map([['key1','value1'],['key2','value2']])", "args": [ ] }
The Chrome will return a empty list by
[null]
The Firefox will return a empty object by
{}
As I thought, the expected value might same as Firefox did, it might be a defect on ChromeDriver, so address a ticket on there for tracking https://bugs.chromium.org/p/chromedriver/issues/detail?id=4031
Finally, I think the original āFor a mapā might point to a object.
How can we reproduce the issue?
Below Code are under Chrome
Map:
Code 1
((JavascriptExecutor) driver).executeScript("return new Map([['key1','value1'],['key2','value2']])");
Code 2
((JavascriptExecutor) driver).executeScript("return new Map()");
Set:
((JavascriptExecutor) driver).executeScript("return new Set()");
All above code will return the empty list just like below execution:
((JavascriptExecutor) driver).executeScript("return [null]");
Relevant log output
2022-02-12 17:40:41 [Forwarding executeScript on session 18038b0c57e548a03be48eaa79260bcd to remote] DEBUG o.a.netty.request.NettyRequestSender.pollPooledChannel(593) - Using pooled Channel '[id: 0xdd3430a4, L:/127.0.0.1:10332 - R:localhost/127.0.0.1:58332]' for 'POST' to 'http://localhost:58332/session/18038b0c57e548a03be48eaa79260bcd/execute/sync'
2022-02-12 17:40:41 [Forwarding executeScript on session 18038b0c57e548a03be48eaa79260bcd to remote] DEBUG o.a.netty.request.NettyRequestSender.sendRequestWithOpenChannel(251) - Using open Channel [id: 0xdd3430a4, L:/127.0.0.1:10332 - R:localhost/127.0.0.1:58332] for POST '/session/18038b0c57e548a03be48eaa79260bcd/execute/sync'
2022-02-12 17:40:42 [AsyncHttpClient-1-2] DEBUG o.a.netty.handler.HttpHandler.handleHttpResponse(70) -
Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
POST /session/18038b0c57e548a03be48eaa79260bcd/execute/sync HTTP/1.1
User-Agent: selenium/4.1.2 (java windows)
Content-Length: 88
Content-Type: application/json; charset=utf-8
host: localhost:58332
accept: */*
Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
cache-control: no-cache
content-length: 16
2022-02-12 17:40:42 [AsyncHttpClient-1-2] DEBUG o.a.netty.channel.ChannelManager.tryToOfferChannelToPool(270) - Adding key: http://localhost:58332 for channel [id: 0xdd3430a4, L:/127.0.0.1:10332 - R:localhost/127.0.0.1:58332]
Operating System
Win10
Selenium version
Java 4.1.2
What are the browser(s) and version(s) where you see this issue?
Chrome 64 bit 98.0.4758.82
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 98.0.4758.80
Are you using Selenium Grid?
No
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I think if you follow the algorithm at https://w3c.github.io/webdriver/#dfn-internal-json-clone-algorithm a Map doesnāt fit the given definition of ācollectionā, so we end up in https://w3c.github.io/webdriver/#dfn-clone-an-object which creates a new object. A Map doesnāt have enumerable properties, so it ends up being an empty object.
This isnāt very useful, but itās well defined (WebDriver-BiDi will do better here). Firefox seems to be correct and a testcase would help other implementations align their behaviour.
@alaahong since this isnāt really a Selenium issue and we arenāt getting the conversation Iād hoped for, Iām going to close. The next step to address this would be to PR a test with the behavior you think is correct here: https://github.com/web-platform-tests/wpt/blob/c95ef3bcb5/webdriver/tests/execute_script/execute.py
Then it is up to w3c to figure out.