OliverDeLange
OliverDeLange

Reputation: 633

How to get iOS alert text in appium 1.6

Before upgrading to XCode 8 and subsequently Appium 1.6 and IOS 10 for some appium tests, I used to be able to use the below XPath to capture the main text in an alert.

@iOSFindBy(xpath = "//UIAAlert/UIAScrollView/UIAStaticText[2]")
private MobileElement alertText;

However something has changed and this no longer works. I would still like to be able to assert on the alert text and don't want to use the IOSMobileCapabilityType.AUTO_DISMISS_ALERTS capability.

Has anyone found a way to get at the alert text?

Bonus question: Where is all this XPath documented? I found it on some random forum, but I can't find any official documentation or figure out how it relates to a captured View Hierarchy in XCode.

Upvotes: 1

Views: 1436

Answers (1)

OliverDeLange
OliverDeLange

Reputation: 633

Answering my own question in case it helps anyone else. Due to the appium inspector not working with XCode8, the best way to print the screen layout XML is just to do a System.out.println(driver.getPageSource());

Then you can follow the structure and do something like

@iOSFindBy(xpath = "//XCUIElementTypeAlert//XCUIElementTypeStaticText[2]")
private MobileElement alertText;

I got that from this question: Finding elements by xpath in Appium using XCUITEST driver

Upvotes: 1

Related Questions