Gatling 2. Snapshort. Not existing xpath return value

Hello!

I have a scenario, where I have to request the page in a loop taking one parameter for every request from the response to the previous one while the response contains the data for the next request.

For this scenario I check does the xpath exist and then I save variable (if the xpath exist) or exit request if xpath doesn’t exist.

My code is:

val request_new_dictionary = asLongAs(session => session(“count_sync”).as[String] != “0”){

exec(http(“request_new_dictionary”)

.post("""/test/mobile""")

.headers(headers_Content_Length_0)

.param(""“request”"", “”" “”")

.check (

xpath(“count(/response/dictionary)”)

.find.saveAs(“count_sync”)

)

.check(

xpath(“string-length(/response/dictionary[1]/@sync_ts)”)

.find

.saveAs(“length_sync”)

)

.check(

xpath("/response/dictionary/@sync_ts")

.find

.saveAs(“dictionary_sync”)

)

But then request_new_dictionary: KO xpath(/response/dictionary/@sync_ts).exists: found nothing

In log I see, that:
Session:

Session(Server synchronization without login,5895774428790541872-0,Map(424f6e64-a784-4728-a6f2-9e5735175c0c → 0, length_sync → 23, dictionary_sync → 2014.07.18 16:54:31.468, timestamp.99c47197-e0b6-4c47-910c-dabe88bea2aa → 1405698080156, 99c47197-e0b6-4c47-910c-dabe88bea2aa → 506, count_sync → 1, gatling.http.cookies → CookieJar(Map(192.168.203.187 → List(Cookie: domain=192.168.203.187, name=JSESSIONID, value=txRKJDudlZeAY5wDJpB6rZ3qTiCTU4XCqUm43aQvuV8x8lh0dBdW!1951985397, path=/, maxAge=-1, secure=false))), timestamp.424f6e64-a784-4728-a6f2-9e5735175c0c → 1405698079226),1405698079223,2270,List(),List(KO),List(),List(99c47197-e0b6-4c47-910c-dabe88bea2aa, 424f6e64-a784-4728-a6f2-9e5735175c0c))

length_sync → 23
count_sync → 1
dictionary_sync → 2014.07.18 16:54:31.468

Why this variables has value, if xpath didn’t exist?

Logically, because it was set in a previous iteration.

But how can I return it real value? Because I need to get out of a loop