I am trying to return a JSONArray from JavascriptExecutor. Normally I can goto chrome browser and goto chrome's dev console and type: "___grecaptcha_cfg.clients[0]"
which returns something similiar to this:
Though when I try this:
JavascriptExecutor js = (JavascriptExecutor) Browser;
Object o = (Object) js.executeScript("return ___grecaptcha_cfg.clients[0];");
I get:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Maximum call stack size exceeded (Session info: chrome=69.0.3497.100) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),
platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
Any idea of how I can overcome this?
Thanks
UPDATE
It seems if I use:
Object o = (Object) js.executeScript("return ___grecaptcha_cfg.clients[0].Cy.C;");
I get back:
{action=null, badge=bottomright, bind=null, callback={}, content-binding=null, pool=null, preload=null, s=null, sitekey=flkgjsfldkjgsfdg, size=invisible, stoken=null, tabindex=null, theme=null, type=image}
which is what I am looking for, but the Cy.C
is constantly changing. I need to be able to parse out the correct value that may change which currently is:
Cy.C
I'm assuming the value is too long? How could I correct this issue?
Update 2
using:
String script = "return JSON.stringify(___grecaptcha_cfg.clients[0]);";
String str = (String) js.executeScript(script);
returns me unknown error: Converting circular structure to JSON
From searching around it seems my issue may be infinite recursion? Any suggestions on how to get around this? I do not need the returned object to be in json format, I just need to be able to parse out whether through a regex expression or something else: 'Cy.C' which I can find by looking for callback={}
or sitekey={}
so I can build a string to call the callback.
If the return JSON object is complex, you can convert it to a string and return. Then convert the JSON string in JAVA code.
String script = "return JSON.stringify(___grecaptcha_cfg.clients[0].Cy.C);";
String str = (String) js.executeScript(script);
// Using JSON-Java lib to convert JSON string to JSON Java Object.
//
//
The reason unknown error: Maximum call stack size exceeded
was throwing was because the object I was searching for was way too complex.
since I saw alot of unanswered posts relating to similar things I will post what I did to solve it:
String script = "for (var prop in ___grecaptcha_cfg.clients[0])"
+"{"
+" return '___grecaptcha_cfg.clients[0].' + prop"
+"}";
System.out.println(script);
Object objects = (Object) js.executeScript(script);
System.out.printl(objects);
I am only pulling the first property here.. And from what I saw unless I iterated over the whole object I wouldn't get the correct order.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.