question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS app with multiple web views only has one web view context and one window handle in that context

See original GitHub issue

The problem

There doesn’t appear to be a working way to switch contexts or window handles from one iOS web view to another, as there seems to only ever be one web view context (with a name that starts with “WEBVIEW_”) and one window handle in that context. Furthermore, attempting to switch window handles in that one context – which admittedly doesn’t make too much sense given there’s only one window handle to begin with, and it seems to already be set to that one by default – hangs Appium Server and the connection eventually times out.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.10.0 (via Appium.app)
  • Last Appium version that did not exhibit the issue (if applicable): N/A
  • Desktop OS/version used to run Appium: macOS Mojave 10.14.2
  • Node.js version (unless using Appium.app|exe): I’m using Appium.app
  • Mobile platform/version under test: iOS 12.1
  • Real device or emulator/simulator: Emulator (iPhone XR)
  • Appium CLI or Appium.app|exe: Appium.app 1.10.0

Details

I’ve got a pretty simple app that has two tabs that contain one view each, where each view per tab contains a single web view (WKWebView) that navigate to different URLs when the app is started. No matter what I do, it seems the only web view context available and its one window handle is always set to the first web view, with seemingly no mention in the logs of the latter web view in the other tab; this behavior holds even when I switch tabs, where the web view from the first tab is the only one with a corresponding context and window handle returned.

Perhaps related: attempting to “switch” to this one window handle times out, i.e. the connection hangs for a long while and nothing happens, but I see in the Appium logs that the request was relayed.

Link to Appium logs

https://gist.github.com/jamespizzurro/785e9ee58fd09c70c3cdf6cce08a4afa

Code To Reproduce Issue [ Good To Have ]

This isn’t a complete working example, just a Java code snippet, but hopefully it’s self-explanatory what I’m trying to do:

// assumption: this.driver is set to a properly-configured instance of IOSDriver

Set<String> contextNames = this.driver.getContextHandles();
// ^ returns only one context
for (String contextName : contextNames) {
    if (!contextName.startsWith("WEBVIEW_")) {
        continue;
    }

    this.driver.context(contextName);

    Set<String> windowNames = this.mobileDriver.getWindowHandles();
    // ^ returns only one window handle
    for (String windowName : windowNames) {
        this.mobileDriver.switchTo().window(windowName);
        // ^ Appium hangs during execution of the line above; this is reflected in the logs I've provided

        // TODO: do stuff with the content of the web view here
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
imurchiecommented, Mar 24, 2020

Sounds good. In 1.17.0 there is also a capability, webviewConnectTimeout, to specify a length of time (in ms) to poll on the server side. It will wait up to that long for a webview to be present. Otherwise the endpoint checks with the WebInspector and returns whatever is returned, so it Safari isn’t reporting it yet, it won’t be returned.

If an issue with webviews comes up, feel free to also mention me in the issue. I check issues but that will flag it to me faster generally speaking.

0reactions
imurchiecommented, Mar 26, 2020

Awesome! Glad to hear it helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WKWebView | Apple Developer Documentation
A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports...
Read more >
How to Accurately Select Webviews Using the `fullContextList ...
If multiple webviews are present in the current view, we can check the urls or titles of each so we can make sure...
Read more >
Context cannot find webviews on 1.3.1 on iOS - Appium Discuss
I am unable to find webviews using context. Set<String> contextNames =webDriver.getContextHandles(); System.out.println(contextNames.size()) ...
Read more >
Appium: Switch to Native & Web-view context for Hybrid App
In this video, we are going to see how we can switch from Native context to Webview context to automate hybrid app in...
Read more >
WebSettings - Android Developers
If a WebView has been destroyed, any method call on WebSettings will throw an ... Gets whether JavaScript running in the context of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found