question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

[šŸ› Bug]: Incorrect description on JavascriptExecutor.executeScript

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jgrahamcommented, May 13, 2022

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.

1reaction
titusfortnercommented, May 13, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavascriptExecutor cannot be resolved to a type - Stack Overflow
I believe you are missing a boolean statement in your js-snippet. Try ((JavascriptExecutor) driver).executeScript("arguments[0].
Read more >
JavascriptExecutor in Selenium Complete Guide
JavascriptExecutor in Selenium examples explained with all details. You will learn all executeScript and executeAsyncScript methodsĀ ...
Read more >
How to Debug WebDriver JavascriptExecutor in Java
Summary Ā· Run your code as early as you can, to avoid writing a lot of code that you have to debug Ā·...
Read more >
Solutions to The Click Problem With Selenium & Java
One of the most fundamental interactions during UI automation testing is done by automating click operations over elements on a web page. ForĀ ......
Read more >
How to Scroll into view in Selenium Webdriver
You might have a requirement to scroll down the page but this requirement was different, so here I used Java Script executor, which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found