appium: Unable to find WEBVIEW context with iOS 13

The problem

I am unable to find WEBVIEW context using driver.contexts. It only shows [‘NATIVE_APP’] using get_all_context. I have no problem getting and switching to WEBVIEW using Appium 1.13 with iOS 12.0. However, recently I want to upgrade to iOS 13 using the latest Appium. I keep running into this problem.

Environment

  • Appium version: 1.17.1-beta.0
  • Last Appium version that did not exhibit the issue: 1.13 + iOS 12.0
  • Desktop OS/version used to run Appium: MacOS 10.15.4 / Xcode 11.4
  • Node.js version: 13.12.0
  • Npm or Yarn package manager: 6.14.4
  • Mobile platform/version: iOS 13.0
  • Real device or emulator/simulator: iOS Simulator
  • Appium CLI or Appium.app|exe: Appium CLI
/usr/local/lib
└─┬ appium@1.17.1-beta.0
  ├─┬ appium-ios-driver@4.6.2
  │ └── appium-remote-debugger@4.5.0 
  └─┬ appium-xcuitest-driver@3.21.1
    └── appium-remote-debugger@8.9.0 

Details

There is no issue with Appium 1.13 + iOS 12.0 switching webview in my app. I don’t know what I did wrong in this setup. I have already update everything to the latest version as I can. It seems like appium can not find any WEBVIEW at all, since I keeps getting only [NATIVE_APP]. I have tried:

  1. Uninstall and reinstall appium CLI both 1.17.1 and beta
  2. Add Capabilities like: ‘fullContextList’: True I am still unable to resolve this issue.

Link to Appium logs

GIST Link : https://gist.github.com/jerislee/54e9cf4fc7c944673b779b10b6de64dc Part of important log : https://gist.github.com/jerislee/82c6722b6e9157dbabcf0e43e6378107

Code To Reproduce Issue [ Good To Have ]

    def switch_context(self, context):  # context = 'WEBVIEW' / 'NATIVE_APP'
        time.sleep(10)
        self.logger.info("[Automation Log]: before switch " + self.driver.current_context)

        while context not in self.driver.current_context:
            if context == "WEBVIEW":
                self.logger.info(self.driver.contexts)
                try:
                    self.driver.switch_to.context(self.driver.contexts[1])
                except BaseException as msg:
                    self.logger.info(msg)
            elif context == "NATIVE_APP":
                self.driver.switch_to.context(context)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 45 (21 by maintainers)

Commits related to this issue

Most upvoted comments

Still having issues with this. Here is a repro using Appium Desktop - Get All Contexts

ios 13.4 appium 1.17.1-1

Capabilities: { “app”: “app”, “platformName”: “iOS”, “platformVersion”: “13.4”, “deviceName”: “iPhone 11 Pro Max 13.4”, “automationName”: “XCUITest”, “webviewConnectTimeout”: “90000”, “safariLogAllCommunication”: true }

for(int i = 0; i<30; i++) { Thread.sleep(1000); Set<String> contextNames = driver.getContextHandles(); for (String contextName : contextNames) { System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1driver.quit(); } }

works for me.

For iOS 16.4 or above, for anyone who lost their minds trying to debug this, there was a recent change where you need to set .isInspectable on the WKWebView object to true (see https://webkit.org/blog/13936/enabling-the-inspection-of-web-content-in-apps/) and re-compile your builds.

@martinfrancois Thanks for the update. Yes in my case Web Inspector is enabled as it is a prerequisites. But yes in my case the issue was different. I fixed it by resign it manually using codesign. And In of the case webviewConnectTimeout = 90000 is helped me and it was taking time.

How about increasing APP_CONNECT_INTERVAL_MS?

the socket would hang up

hm… Can the webview communicate with Safari Web Inspector? I mean connect with Web Inspector -> inspect the element etc via it

If it could, perhaps we need to find another way to communicate with WebViews https://github.com/appium/appium-remote-debugger#safaris-version-of-the-webkit-api

@mykola-mokhnach I am getting the same issue with same scenario. Am able to get Webview in Safari browser when I checked this manually but yes of course the DOM element are not able to loaded. Tried Appium version: 1.15.1 and 1.17.0

  • Is the web view visible in Safari remote debugger?
  • Have you tried to add a timer for web view detection?