java - how to get JSessionID in PhantomJS -
i not sure if question related phantomjs or simple javascript.
i using ghostdriver open webpage , trying capture response headers. ghostdriver executes javascript , adds onresourcereceived event.
like this:
string responsescript = "var page = this,"+ "jsonresponse = \"\";"+ "page.onresourcereceived = function (res) {"+ "console.log(json.stringify(res));" /* line works fine want pass data somehow java program. that, came below alternative failing*/ "jsonresponse = jsonresponse + json.stringify(res, undefined, 4);"+ "};"+ "function getjsonresponse(){"+ "return jsonresponse;"+ "}"; ghostdriver.executephantomjs(responsescript); ghostdriver.get("cnn.com"); ghostdriver.executephantomjs("getjsonresponse();");
it fails below message:
{message=can't find variable: getjsonresponse, line=1, stack=referenceerror: can't find variable: getjsonresponse
i want response headers in string variable in java can jsessionid in it..
because of poor javascript skills not able solve simple problem..
i don't know why took long route after going through examples on ghostdriver(link) ..its 2 lines of code
so happy..now can sleep peacefully :)
string responsescript = "return json.stringify(this.cookies);"; object object = phantom.executephantomjs(responsescript); system.out.println(((string)object));
Comments
Post a Comment