I'm not a doctor or a pharmacist. But just because it has the same ingredients doesn't mean it is the same. The way the medication is packaged, what fillers it has, etc. may have an impact on the way it works. Anecdotally I've heard of people having a different reaction to namebrand and generic because of some of these factors.
Good point, and worth keeping in mind! At the same time, the generics are often so much cheaper it's worth a try. I take Claratin daily for allergies and the Costco version is literally 10% the cost of name brand. It's astounding how much of a markup basic OTC drugs can have.
It's even more exciting in GMO-produced drugs like insulin where there are no generics, just 'biosimilars' because they're not made by the exact same strain of yeast/bacteria. Also then the excipients vary from brand to brand. For some reason some people have almost no effect from one insulin compared to another.
Vitamins and health supplements too. My mom works at a pretty big brand name one of them and they literally package the exact same stuff for a generic brand that's half the price.