How to extract an value from HTMl

1,056 views
Skip to first unread message

twinkle

unread,
Aug 20, 2015, 8:30:51 AM8/20/15
to Gatling User Group
Hi,

1. How to extract an value from HTML

a href="/apps/.....do?actionType=adminPage&authtoken=d8f8f981-f7a9-4ba1-9cd9-03e9b60a91cb" onClick = "javascript:

how to extract authtoken value from the above one.

2 . how to extract from jsonResponse want to store in each item in variable
({"data":"1, 2, 3}),


Thanks in Advance


Abhinav Gogna

unread,
Aug 20, 2015, 9:52:28 AM8/20/15
to Gatling User Group
Gatling http checks page has all the solutions. http://gatling.io/docs/2.1.7/http/http_check.html

1) if you want to extract from string then use Regex. If you want the the whole href, you can also use CSS (link).

2) For Json, search for jsonPath on this page.

twinkle

unread,
Aug 25, 2015, 12:53:25 AM8/25/15
to Gatling User Group
Hi,

I tried with both regex and css but  i am not able to get the value of authtoken (refered above)

1 .check (regex(""""authtoken"="([^"]*)""").saveAs("AuthToken")) 
2. .check (css("href=\"/apps/.....do?actionType=adminPage", "authtoken").saveAs("AuthToken"))

with css i am getting the below error

,UTF-8),Map(),2285,UTF-8,RequestTimings(1440478289443,1440478289445,1440478289976,1440478289976)))), forwarding user to the next action
jodd.csselly.CSSellyException: Invalid combinator <=>. (state: 6)
at jodd.csselly.CSSellyLexer.yylex(CSSellyLexer.java:776) ~[jodd-lagarto-3.6.5.jar:3.6.5]
at jodd.csselly.CSSelly.parse(CSSelly.java:38) ~[jodd-lagarto-3.6.5.jar:3.6.5]
at jodd.csselly.CSSelly.parse(CSSelly.java:73) ~[jodd-lagarto-3.6.5.jar:3.6.5]

twinkle

unread,
Aug 25, 2015, 2:23:19 AM8/25/15
to Gatling User Group


On Thursday, August 20, 2015 at 6:00:51 PM UTC+5:30, twinkle wrote:
 using Gatling 2.2  version

Abhinav Gogna

unread,
Aug 26, 2015, 11:36:07 AM8/26/15
to Gatling User Group
Try following

.check (regex("""authtoken=([^"]*)""").saveAs("Authtoken") //- https://regex101.com/

2 for CSS parser I will need entire html. You can use the following site to test out CSS parser http://try.jsoup.org/

twinkle

unread,
Aug 27, 2015, 1:24:54 AM8/27/15
to Gatling User Group


On Thursday, August 20, 2015 at 6:00:51 PM UTC+5:30, twinkle wrote:
  • Thanks Abhinav the first option works fine. i am able to extract the token value.

  • Can you help to get value from json Response using json parser 
           My Json String =({"data":"1, 2, 3})


Abhinav Gogna

unread,
Aug 27, 2015, 12:22:23 PM8/27/15
to Gatling User Group
Sure
 
check(jsonPath($.[data]).saveAs("myData"))

You can use this link to test your json parser yourself https://jsonpath.curiousconcept.com/ - Select Stefan Goessner implementation

Quick tutorial on jsonPath syntax - http://goessner.net/articles/JsonPath/

twinkle

unread,
Aug 28, 2015, 4:41:30 AM8/28/15
to Gatling User Group


On Thursday, August 20, 2015 at 6:00:51 PM UTC+5:30, twinkle wrote:
Hi Abhinav,

Thanks again.

i used jsonPath("$")previously  so i didn't get what i am expected,Thanks it is also working fine with jsonPath("$.data")..

Reply all
Reply to author
Forward
0 new messages