So we know that several different ancient and very early medieval empires used war elephants in combat. While they were sometimes beaten, they were generally pretty effective in combat, especially against troops who had never seen them before.
My question is, why did the use of elephants die out? The last known battle i could find on them was when the Sassanians were defeated by the Muslims at Al-Qadisiyyah.
In a way you kind have already answered your question. While they were pretty effective in combat the main reason they were useful was the fear element of encountering war elephants on the field. As time went on though commanders and troops that were experienced understood how to combat them. One of the main counter tactics was to scare them driving them into a rampage that often did more harm to the army utilising them then to the army they were supposed to attack.
Additionally the logistics of using them must have been a nightmare as they aren't natives of Europe and I believe most of the Middle East therefore making it difficult to bring them to the battlefields.