# Strange Behavior: Dictionary Key Found in Check but Not in FOR Loop

**URL:** <https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444>\
**Category:** Robot Framework\
**Created:** [9 December 2025 20:14 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444 "2025-12-09T20:14:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauro](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mauro](https://forum.robotframework.org/u/Mauro)\
**Post date:** [9 December 2025 20:14 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/1 "2025-12-09T20:14:21Z")

</div>

Hi everyone!  
I’m learning RF and struggling with something…  
I created some dictionaries and added them to a list, then I tried to iterate over it using a FOR loop, but the result is: “Dictionary does not contain key ‘…’”.  
However, before the FOR loop, I tested the dictionary using the “keyword Dictionary Should Contain Key” — it passes the check.  
I don’t know what I’m doing wrong.  
Here’s my code:

```python
Iterar sobre lista de dicionários para exibir seus valores
        
    Log Dictionary dictionary=${TotalDebitos}
    
    ${TotalDebitos}[valorEncontrado]= Set Variable 1000,00
    ${DebitosProcessados}[valorEncontrado]= Set Variable 700,00
    ${DebitosPendentes}[valorEncontrado]= Set Variable 300,00

    Log Dictionary dictionary=${TotalDebitos}

    Dictionary Should Contain Key dictionary=${TotalDebitos} key=valorEncontrado

    Dictionary Should Contain Item dictionary=${TotalDebitos} key=valorEncontrado value=1000,00

    FOR ${dicionario} IN @{tabelaResultado}
        ${Campo}= Get From Dictionary ${dicionario} campo
        ${Locator}= Get From Dictionary ${dicionario} locator
        ${valor}= Get From Dictionary ${dicionario} valorEncontrado
        Log Campo: ${campo}
        Log Locator: ${locator}
        Log Valor encontrado: ${valor}
    END

```

The result:

 ![ErroRF](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/0/01e982dc160f0d85bf935055505fc869aabba8d5.png)  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [9 December 2025 22:33 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/2 "2025-12-09T22:33:48Z")

</div>

> [@Mauro](#):
>
> `FOR ${dicionario} IN @{tabelaResultado}`

Before this loop, please do a `Log Many ${tabelaResultado[0]}` .  
Probably it really does not have the key `valorEncontrado`.

---

<div class="post-metadata">

**Author:** ![hyytiainen](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hyytiainen](https://forum.robotframework.org/u/hyytiainen)\
**Post date:** [10 December 2025 06:26 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/3 "2025-12-10T06:26:00Z")

</div>

In the log the first red ITERATION line reveals the dictionary content and that the requested key is not in the dictionary. So the dictionary content is as it was when it was added into the list.  
It seems that later modifications into the original dictionary (after adding it to a list) are not affecting the dictionary in the list.

---

<div class="post-metadata">

**Author:** ![Mauro](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mauro](https://forum.robotframework.org/u/Mauro)\
**Post date:** [10 December 2025 12:09 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/4 "2025-12-10T12:09:05Z")

</div>

> [@Mauro](#):
>
> `Set Variable`

Hi, Hélio! I ran the keyword `Log Many ${tabelaResultado[0]`, like you said, and the output shows that the dictionary does not contain the key I’m looking for. I assume I’m making a mistake when adding the key–value pair, but I don’t know at which point. I’ve already tried initializing the key without a value in the dictionary and then assigning the value later. I also tried adding it using `Set To Dictionary dictionary=${TotalDebitos} valorEncontrado=R$ 1.000,00 D`, but the result was the same.  
Thanks for the help!

---

<div class="post-metadata">

**Author:** ![Mauro](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mauro](https://forum.robotframework.org/u/Mauro)\
**Post date:** [10 December 2025 12:32 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/5 "2025-12-10T12:32:35Z")

</div>

Hi, Sami! After your message, I tried again without using the list. I just created the dictionary and tried adding the key–value pair, and then it worked. However, I would like to keep my original idea of having several dictionaries in a list so I can iterate over it and then perform the checks on each dictionary’s values.  
Could my logic be wrong? Is this not possible?

Thanks!

---

<div class="post-metadata">

**Author:** ![hyytiainen](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hyytiainen](https://forum.robotframework.org/u/hyytiainen)\
**Post date:** [10 December 2025 13:31 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/6 "2025-12-10T13:31:00Z")

</div>

Hi Mauro,

You can update the values straight to the list of dictionaries, something like this:

```python
# ${TotalDebitos}[valorEncontrado]= Set Variable 1000,00
# ${DebitosProcessados}[valorEncontrado]= Set Variable 700,00
# ${DebitosPendentes}[valorEncontrado]= Set Variable 300,00
Set To Dictionary ${tabelaResultado}[0] valorEncontrado=1000,00
Set To Dictionary ${tabelaResultado}[1] valorEncontrado=700,00
Set To Dictionary ${tabelaResultado}[2] valorEncontrado=300,00

```

or after updating dictionaries you could recreate the original list with

```python
${TotalDebitos}[valorEncontrado]= Set Variable 1000,00
${DebitosProcessados}[valorEncontrado]= Set Variable 700,00
${DebitosPendentes}[valorEncontrado]= Set Variable 300,00
VAR @{tabelaResultado} = ${TotalDebitos} ${DebitosProcessados} ${DebitosPendentes} 

```

---

<div class="post-metadata">

**Author:** ![Mauro](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Mauro](https://forum.robotframework.org/u/Mauro)\
**Post date:** [11 December 2025 11:05 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/7 "2025-12-11T11:05:22Z")

</div>

> [@Mauro](#):
>
> ```python
> {Campo}= Get From Dictionary ${dicionario} campo
> ${Locator}= Get From Dictionary ${dicionario} locator
> ${valor}= Get From Dictionary ${dicionario} valorEncontrado
> Log Campo: ${campo}
> Log Locator: ${locator}
> Log Valor encontrado: ${valor}
> 
> ```

Thanks, Sami!  
Recreating the list after updating the dictionary solved my problem!  
Thank you very much for helping me!

---

<div class="post-metadata">

**Author:** ![hyytiainen](https://avatars.discourse-cdn.com/v4/letter/h/ecd19e/32.png) [@hyytiainen](https://forum.robotframework.org/u/hyytiainen)\
**Post date:** [11 December 2025 12:23 UTC](https://forum.robotframework.org/t/strange-behavior-dictionary-key-found-in-check-but-not-in-for-loop/9444/8 "2025-12-11T12:23:27Z")

</div>

Great, no problem.

Happy to help.
