# Dynamic value in string

**URL:** <https://forum.robotframework.org/t/dynamic-value-in-string/7554>\
**Category:** Robot Framework\
**Created:** [15 July 2024 21:17 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554 "2024-07-15T21:17:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [15 July 2024 21:17 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554/1 "2024-07-15T21:17:16Z")

</div>

How to handle dynamic value inside the string. for example below 10 and 15 will be dynamic value

Would you consider making an additional gift of $10 every month 15th to ?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [16 July 2024 01:31 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554/2 "2024-07-16T01:31:41Z")

</div>

Hi @grarun11,

This is covered in the documentation for [using variables](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#using-variables)

For your specific question would be something like this:

```python
   VAR ${giftammount} 10
   VAR ${dayofmonth} 15
   VAR ${qstring} Would you consider making an additional gift of \$${giftammount} every month ${dayofmonth}th to ?
   Log ${qstring}

```

Dave.

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [16 July 2024 10:58 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554/3 "2024-07-16T10:58:53Z")

</div>

Thanks Damies.

But I don’t know the value. Its dynamic.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [16 July 2024 11:24 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554/4 "2024-07-16T11:24:23Z")

</div>

Hi @grarun11 ,

The first 2 lines was just to give the variables a value so this was a working example, the 3rd line is what you need for your test case, just replace the variable names with the ones you want.

Dave.

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [16 July 2024 17:08 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554/5 "2024-07-16T17:08:48Z")

</div>

Hi,

Can your precise where the values come from?

- Either from a locator in the page (with a Get Text or Attribute Value)
- From a condition that gives 10 and 15 (here I would use a corresponding table)
- If the values are totally random, then I don’t see how you can validate it’s correct if you don’t know what expect. Here the best would be to use regex or glob pattern to replace the values in the obtained variable. At least regex verifies the text, and returns the two values in the string for check.

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![grarun11](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@grarun11](https://forum.robotframework.org/u/grarun11)\
**Post date:** [16 July 2024 17:33 UTC](https://forum.robotframework.org/t/dynamic-value-in-string/7554/6 "2024-07-16T17:33:25Z")

</div>

15 is current date so I used now{} but 10 varies depends on the amount. I can use gettext and get that value
