Unable to find element on iOS 16+ with appium 2.5.1

Using below version for iOS automation.
Appium 2.5.1
iOS 16.7.5 and 17.3
Xcode 15.2/15.3
XCUITestDriver 5.0.0/7.1.0
Selenium 4.11/4.16/4.18
find_element returns dict object as ‘{“wrapped”:“xpath”,“actions”:,“chain”:false}’
We are switching correctly to Webview as it is a hybrid app. Same code is working fine for Android.
Has anyone encountered this error recently ?
Log is attached

Not so easy :slight_smile:
One of issue could be that you have several WebViews in app. Check this first …

Getting only one webview context as below. And We are switching to this webview_5075.1 for e.g

Responding to client with driver.getContexts() result: [{“id”:“NATIVE_APP”},{“id”:“WEBVIEW_5075.1”,“title”:“Institution List | NavXXXX360”,“url”:“ionic://zzz-mobile.NavXXXX.zzz.com#/institution/list/”,“bundleId”:“com.xxx.xx”}]

Attached is the log file.

Untitled.txt (188.9 KB)

next step. Open Safari on Mac and check that you can see your page content. More to read - How to Debug Websites on iPhone Safari | BrowserStack

Able to see the page content.

When trying to get page source after switching to WEBVIEW, it returns the dict similar to finding element.
Context switched to : WEBVIEW_3278.1
page source : {‘wrapped’: ‘return document.documentElement.outerHTML’, ‘actions’: , ‘chain’: False}

If you able to switch and see webView in Safari, same should be available with Appium.

Not sure if it is actually switching the context . All though getCurrentContext returns WEBVIEW. Any reason why pageSource is returning the dict instead of returning the actual html ?
We are guessing any mismatch between iOS, Xcode, Appium, XCUITest compatibility. However we tried all major version combinations. Or either there is an issue with the app itself which is preventing to access the DOM and Webelements. Any idea ?

This is WEBView! Not native. So do not expect here similar output. If you need to have some readable HTML without javascript code you need get HTML code similar to:

String result = driver.findElement(By.cssSelector("body")).getAttribute("outerHTML")
// By.cssSelector("body") = get body element of WebView
// getAttribute("outerHTML") - get element HTML code

Thanks. Tried with above code. get_driver(context).find_element(By.CSS_SELECTOR, “body”) returns the same dict and hence get_attribute(‘outerHTML’) throws error saying {AttributeError}‘dict’ object has no attribute ‘get_attribute’

Screenshot 2024-03-13 at 4.31.40 PM

Any help would be appreciated. I am still stuck at the same thing. Also tried to find element with iOS Predicates like XCUIElementTypeOther. But no luck. Anyhow its returning the dict.