SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
346 stars 194 forks source link

ER: add new API in JavscriptExecutor to return JSONObject #4945

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 4945

We hava a large amount of javscript functions, which return a javascript object. 

But,the JavscriptExecutor.executeScript cannot return a JSONObject.
JavscriptExecutor.executeScript only support return Boolean, Long, String, List or
WebElement. 

Could you please add a new API to support returning a JSONObject?

Reported by yuchang.guo on 2012-12-25 03:36:41

lukeis commented 8 years ago
It's undocumented, but most of the driver's support this (HtmlUnit is the exception,
IIRC).  You'll get a Map<String, Object> though, not a JSONObject.

Map<String, Integer> map = (Map<String, Integer>)  ((JavascriptExecutor) driver).executeScript("return
{foo: 1, bar: 2}");
System.out.printf("foo: %d\n", map.get("foo"));
System.out.printf("bar: %d\n", map.get("bar"));

Reported by jmleyba on 2012-12-26 20:07:18

lukeis commented 8 years ago
Hi!

Am i right that it's just documentaion request?
Is possibility to return a map enough?

Reported by a.u.savchuk on 2013-09-07 20:07:11

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:45:10