# Set a variable if css succeed without exception

**URL:** https://community.gatling.io/t/set-a-variable-if-css-succeed-without-exception/497
**Category:** Gatling (Open-Source)
**Created:** [July 18, 2013, 2:47pm UTC](https://community.gatling.io/t/set-a-variable-if-css-succeed-without-exception/497 "2013-07-18T14:47:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Florian\_P](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@Florian\_P](https://community.gatling.io/u/Florian_P)
#### Post date: [July 18, 2013, 2:47pm UTC](https://community.gatling.io/t/set-a-variable-if-css-succeed-without-exception/497/1 "2013-07-18T14:47:01Z")

</div>

Hi,  
sorry for harassing, I have another small problem and can’t find a solution…  
I make another list of links (like in my previous message : [https://groups.google.com/forum/#!topic/gatling/1TpcP8ukJKw](https://groups.google.com/forum/#!topic/gatling/1TpcP8ukJKw)) but sometimes the css request may fail and throw an exception. How can I set the variable if the css request succeed ? Here is a part of my code :

> exec(  
> http(“Question ${next\_question}”).get(“${next\_question}”).check(  
> css(“”“#block-system-main .region-two-66-33-first .block-content article”“”, “id”).saveAs(“question\_id”),  
> css(“”“#block-system-main .pane-node-content h2"”“).saveAs(“question\_title”),  
> css(”““form#comment-form””“, “action”).saveAs(“comment\_action”),  
> css(”““form#comment-form input[name=“form\_build\_id”]””“, “value”).saveAs(“comment\_build\_id”),  
> css(”““form#comment-form input[name=“form\_token”]””“, “value”).saveAs(“comment\_token”),  
> css(”““form#answer-node-form input[name=“form\_build\_id”]””“, “value”).saveAs(“answer\_build\_id”),  
> css(”““form#answer-node-form input[name=“form\_token”]””“, “value”).saveAs(“answer\_token”),  
> css(”““form#answer-node-form””“, “action”).saveAs(“answer\_action”),  
> css(”“”.bonita-views-answer-content-pane .view-content article.node.node-answer header h1 a"“”, “href”).findAll.saveAs(“answer\_links”),  
> regex(“”“,“checksum”:”([a-z0-9]+)“}”“”).saveAs(“checksum”)))

The last css request may fail

Many thanks

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [July 18, 2013, 2:53pm UTC](https://community.gatling.io/t/set-a-variable-if-css-succeed-without-exception/497/2 "2013-07-18T14:53:51Z")

</div>

css(""".bonita-… header h1 a""", “href”).findAll.whatever.saveAs(“answer\_links”)

See [https://github.com/excilys/gatling/wiki/Checks#wiki-whatever](https://github.com/excilys/gatling/wiki/Checks#wiki-whatever)  
OK ?

cheers  
Nicolas

---

<div class="post-metadata">

### Author: ![Florian\_P](https://avatars.discourse-cdn.com/v4/letter/f/3be4f8/32.png) [@Florian\_P](https://community.gatling.io/u/Florian_P)
#### Post date: [July 18, 2013, 2:57pm UTC](https://community.gatling.io/t/set-a-variable-if-css-succeed-without-exception/497/3 "2013-07-18T14:57:38Z")

</div>

That’s it 🙂
