I’m assuming this is on Android?
Reading the text out of an alert is a recipe for disaster. If the alert is raised by a different context, you will need to switch to get it, (although that looks like it’s not a problem in this case) but if the alert disappears before you get to read it (a very common problem) you will have a very flakey test case. Only do this for persistent notifications which you want to interact with, otherwise just do not test alerts if you can help it.
Having a test case hinge on a fleeting event can be easily avoided as a source of flakiness by having the developer provide a hook into the app logging or other way, to allow the tester to verify app state. Normally you need to be testing for “outcomes”, try to avoid testing alerts, it’s not a brilliant way to test. Perhaps you are jsut wanting to check that the password was incorrect. When this happens, the login will fail, so that’s the outcome you are interested in. Thing like UI furniture are not a great candidate for automation check because on-screen keyboards often obscure them too. Hope you can find a way to re-design your test case.