Obviously, as noted in a comment, the character might not know about the immunity. But if she does:
Immune to taking damage doesn't mean immune to being hit, and some features trigger (or become available) when you hit, regardless of doing damage. Examples:
Some spells, like Bestow Curse, Hex and the various Smite spells.
Some class features, including: Divine Smite; Divie Strike; Hurl Through Hell; Quivering Palm, Raging Storm; Relentless Avenger; Sign of Ill Omen, Stunning Strike; Totemic Attunement (Wolf); Touch of Death; Unwavering Mark; and many of the Battlemaster Fighter's maneuvers.
Some feats, like Sentinel and Tavern Brawler.
Barbarians below level 15 need to attack to maintain rage.
Non-weapon attacks like shoving or grappling can be used.
Note that features like Hexblade's Curse would not add damage to the initial melee attack, but would trigger on additional damage from something like a Smite.
Also note that there may be tactical reasons to stay engaged without taking the attack action, including: assisting to give advantage to another character; allowing another to Sneak Attack; and being the target for attacks so that others aren't.