Is there a way to extract a JSONArray from JavascriptExecutor in Selenium? Normally, when I try to access it using "___grecaptcha_cfg.clients[0]"
in Chrome's dev console, I get a result similar to this:
https://i.sstatic.net/X8BlS.png
However, when I attempt the following code snippet:
JavascriptExecutor js = (JavascriptExecutor) Browser;
Object o = (Object) js.executeScript("return ___grecaptcha_cfg.clients[0];");
I encounter an error:
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 suggestions on how to resolve this issue?
Thank you
UPDATE
If I use the following code instead:
Object o = (Object) js.executeScript("return ___grecaptcha_cfg.clients[0].Cy.C;");
I receive the desired output:
{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}
The issue lies with the changing value of Cy.C
. How can I handle this dynamically changing value?
Update 2
By using:
String script = "return JSON.stringify(___grecaptcha_cfg.clients[0]);";
String str = (String) js.executeScript(script);
I encounter the error message
unknown error: Converting circular structure to JSON
It seems like I may be running into infinite recursion. Any advice on how to solve this problem? My goal is to parse out the value 'Cy.C' by identifying callback={}
or sitekey={}
within the object.