> I'm sure they must exist somewhere, but battery-powered trams are not popular.

Yes, they do exist. The Alstom Citadis at Rio de Janeiro, which I take often, uses a supercapacitor for small pieces of its route (mostly crossings where the third rail would be damaged too often by vehicle traffic, or be impractical); according to the Wikipedia article (https://en.wikipedia.org/wiki/Alstom_Citadis), the Alstom Citadis at Nice uses batteries for parts of its route (https://www.railway-technology.com/projects/nice-trams/). I'm sure there are others.