getText() is returning null

Hi,

I am trying to get the text from alert message and compare with expected message text, but the element.gettext() is returning ‘null’. How to get the actual message displayed inside the message box.
SeeTestIOSElement alertBody=driver.findElementById(“historyPopUpBody”);
String alertBodyText = alertBody.getText();
String acutalAlertMessage = “Functionality yet to be implemented”;
if (alertBodyText== acutalAlertMessage) {
System.out.print(“Message is correct”);
}
else
{System.out.print(“Message is not correct”);

		}

Why are you comparing strings with “==” and not “equals”?

Regardless, the getText method works for you on other elements? let’s say in the demo app ExperiBank?

Yes, i am using String.equals for comparison. Only for this string getText() is not working and for rest of elements it works fine.

for example:
use the “com.experitest.ExperiBank” and -
driver.findElement(By.xpath("//[@placeholder=‘Username’]")).sendKeys(“company”);
System.out.println(driver.findElement(By.xpath("//
[@placeholder=‘Username’]")).getText());

1 Like

Thanks, i was able to figure out the problem. Now it is returning the text.