# Gatling2: how to perform a simple text for an attribute

**URL:** <https://community.gatling.io/t/gatling2-how-to-perform-a-simple-text-for-an-attribute/742>\
**Category:** Gatling (Open-Source)\
**Created:** [December 23, 2013, 11:11pm UTC](https://community.gatling.io/t/gatling2-how-to-perform-a-simple-text-for-an-attribute/742 "2013-12-23T23:11:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Otheus](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@Otheus](https://community.gatling.io/u/Otheus)\
**Post date:** [December 23, 2013, 11:11pm UTC](https://community.gatling.io/t/gatling2-how-to-perform-a-simple-text-for-an-attribute/742/1 "2013-12-23T23:11:27Z")

</div>

(Very new at this)

The docs for version 1 refer to something like:

doIf( session =\> session.hasAttribute(“blahblah”) ) { … }

This doesn’t work in version 2. The one that _sort of_ works is:

.doIf(session =\> session(“blahblah”).validate[String].map(\_ != “”))

but from this, I get ERROR log messages:

00:10:37.403 [ERROR] i.g.c.action.If - No attribute named ‘blahblah’ is defined

It’s definitely from this code block, as removing the block eliminates the error messages. This suggests this is not the “right” way to test for the existence of an attribute.

Please help.

(PS, there’s probably a better way to do what I’m needing to do, but I’m working with OPC here.)

---

<div class="post-metadata">

**Author:** ![Otheus](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@Otheus](https://community.gatling.io/u/Otheus)\
**Post date:** [December 23, 2013, 11:12pm UTC](https://community.gatling.io/t/gatling2-how-to-perform-a-simple-text-for-an-attribute/742/2 "2013-12-23T23:12:09Z")

</div>

Oops. I meant “test” for an attribute, not text.

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [December 26, 2013, 9:46am UTC](https://community.gatling.io/t/gatling2-how-to-perform-a-simple-text-for-an-attribute/742/3 "2013-12-26T09:46:23Z")

</div>

“hasAttribute” became “contains” in Gatling 2

“validate” handles missing attribute as a blocking error, session(“blahblah”).asOption[String].map(\_ != “”).getOrElse(false) would have produced the expected result, but well… contains is teh way to go! 🙂

---

<div class="post-metadata">

**Author:** ![Otheus](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@Otheus](https://community.gatling.io/u/Otheus)\
**Post date:** [December 30, 2013, 6:47pm UTC](https://community.gatling.io/t/gatling2-how-to-perform-a-simple-text-for-an-attribute/742/4 "2013-12-30T18:47:45Z")

</div>

Great! That did the trick. Thank you.
