Could anyone suggest to me the code to read an iOS toast message. I have read android toast messages using AndroidElement toastElement = driver.findElementByXPath("//android.widget.Toast[1]"); String toastMessage = toastElement.getAttribute("name");
But for iOS toast the above is not working
IOSElement toastElement = driver.findElementByXPath("//ios.widget.Toast[1]"); String toastMessage = toastElement.getAttribute("name");
Use below method , it uses page source to verify the toast message. Works for both iOS and Android.
public boolean isToastMessageDisplayed(String message)
{
boolean isDisplayed = false;
int count=0;
do {
if(mobileDriver.getPageSource().contains(message))
{
isDisplayed=true;
break;
}
Thread.sleep(200);//Add your custom wait if exists
count++;
}while(count<10);
return isDisplayed;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.