Dua when seeing someone in trial
الْحَمْـدُ للهِ الّذي عافاني مِمّا ابْتَـلاكَ...
الْحَمْـدُ للهِ الّذي عافاني مِمّا ابْتَـلاكَ بِهِ، وَفَضَّلَـني عَلى كَثيـرٍ مِمَّنْ خَلَـقَ تَفْضـيلا
Alhamdu lillahil-lathee AAafanee mimmab-talaka bih, wafaddalanee AAala katheerin mimman khalaqa tafdeela
Translation
All praise is for Allah Who saved me from that which He tested you with and Who most certainly favoured me over much of His creation.
When to recite
Said quietly to oneself (not to the afflicted person) when seeing someone in trial or tribulation.
Source / Reference
At-Tirmithi 3/153