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.

Android: Appium does not detect all webviews shown by chrome remote debugger

See original GitHub issue

The problem

Appium’s driver.contexts does not list all webviews shown by chrome remote debugger. Also in some cases if chrome is not running in the background then it doesn’t list all webviews. When i manually start chrome and then run the test using Appium it shows the webview

Environment

  • Appium version (or git revision) that exhibits the issue: 1.10.0 and before
  • Last Appium version that did not exhibit the issue (if applicable): NA
  • Desktop OS/version used to run Appium: Mac OSX 10.14
  • Node.js version (unless using Appium.app|exe): All
  • Mobile platform/version under test: Android 9, 8
  • Real device or emulator/simulator: Read device
  • Appium CLI or Appium.app|exe:

Details

Appium seems to detect available webviews by looking at the output of /proc/net/unix

angler:/ $ cat /proc/net/unix| grep -i webview             
0000000000000000: 00000002 00000000 00010000 0001 01 5144717 @webview_devtools_remote_6142
0000000000000000: 00000003 00000000 00000000 0001 03 5142394 @webview_devtools_remote_6142

Seems like chromedriver has an API to list webviews and it shows all webviews as separate windows. Can we use this logic to fetch the list of webviews entirely through chromedriver as follows?

STEP 1: Launch chromedriver (say on port 8000) and create a new session POST http://localhost:8000/wd/hub/session RESPONSE: {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8)"},"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:55964"},...

STEP 2: Get a list of webviews using the debuggerAddress from the previous response GET http://localhost:55964/json

RESPONSE: ```

[
  {
    "description": "{\"attached\":true,\"empty\":false,\"height\":1584,\"screenX\":0,\"screenY\":210,\"visible\":true,\"width\":1080}",
    "devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@dec090ce558f4dbef3830f7d236d3abecf770594/inspector.html?ws=localhost:64698/devtools/page/C2AA84076605682A9FEC208E94BBF38D",
    "id": "C2AA84076605682A9FEC208E94BBF38D",
    "title": "20190114",
    "type": "page",
    "url": "https://mobileapp.app.com/todaysdeals",
    "webSocketDebuggerUrl": "ws://localhost:64698/devtools/page/C2AA84076605682A9FEC208E94BBF38D"
  },
  {
    "description": "{\"attached\":false,\"empty\":true,\"screenX\":0,\"screenY\":0,\"visible\":true}",
    "devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@dec090ce558f4dbef3830f7d236d3abecf770594/inspector.html?ws=localhost:64698/devtools/page/CC6BB9E0833650D16039C08D47E76AF8",
    "faviconUrl": "https://googleads.g.doubleclick.net/favicon.ico",
    "id": "CC6BB9E0833650D16039C08D47E76AF8",
    "title": "https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader-canary-canary.html",
    "type": "page",
    "url": "https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader-canary-canary.html",
    "webSocketDebuggerUrl": "ws://localhost:64698/devtools/page/CC6BB9E0833650D16039C08D47E76AF8"
  },
  {
    "description": "{\"attached\":false,\"empty\":false,\"height\":181,\"screenX\":0,\"screenY\":0,\"visible\":true,\"width\":1080}",
    "devtoolsFrontendUrl": "http://chrome-devtools-frontend.appspot.com/serve_rev/@dec090ce558f4dbef3830f7d236d3abecf770594/inspector.html?ws=localhost:64698/devtools/page/10C4C9131158C5FEF9E15C3732544FDA",
    "faviconUrl": "https://pubads.g.doubleclick.net/favicon.ico",
    "id": "10C4C9131158C5FEF9E15C3732544FDA",
    "title": "about:blank",
    "type": "page",
    "url": "about:blank",
    "webSocketDebuggerUrl": "ws://localhost:64698/devtools/page/10C4C9131158C5FEF9E15C3732544FDA"
  }
]

STEP 3: Switch to window using window ID C2AA84076605682A9FEC208E94BBF38D from previous response

> curl -X POST "http://127.0.0.1:8000/wd/hub/session/eac131a983ffb4c6df83c98df73e6baf/window" --data '{"name": "CDwindow-C2AA84076605682A9FEC208E94BBF38D"}'
> {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":null}

STEP 4: Check if it switched

> curl "http://127.0.0.1:8000/wd/hub/session/eac131a983ffb4c6df83c98df73e6baf/window"
> {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":"CDwindow-C2AA84076605682A9FEC208E94BBF38D"}

STEP 5: Locate element

> curl -X POST "http://127.0.0.1:8000/wd/hub/session/eac131a983ffb4c6df83c98df73e6baf/element" --data '{"using":"id","value":"id_scfFooter"}'
> {"sessionId":"eac131a983ffb4c6df83c98df73e6baf","status":0,"value":{"ELEMENT":"0.9314698275473243-1"}}

This approach means we only have to create one chromedriver instance even if there are multiple webviews. So this could also fix the issue https://github.com/appium/appium/issues/11820

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ajithvlcommented, Jan 15, 2019

Thanks for the detailed investigation @ajithvl Would you like to push a PR? For us it is probably going to take more time, especially if we want to properly test the change.

@mykola-mokhnach I am not too familiar with Appium codebase. Lemme look into it and get back. I can surely help with testing though.

0reactions
mykola-mokhnachcommented, Nov 16, 2020

Currently the logic of web views extraction is aligned with the one used in Chrome. The list of web view pages/windows could be retrieved using the recently added mobile: getContexts API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appium only show native app context, is does not recognises ...
I am experiencing an issue with Appium and iOS simulator, where a call to contexts() returns only NATIVE_APP, and no webview. This happens...
Read more >
Appium only show native app context, is does not recognises ...
Appium only show native app context, is does not recognises the webview ... The app does have the webview visible (verified by chrome...
Read more >
Cannot find WebView when searching for context in Hybrid ...
Go to Chrome devices remote debugging (chrome://inspect/#devices) and check if there is any WebView. If no, that means you have native app. Hi...
Read more >
Can't find elements on a webview page of an android Native ...
I am not able to find the elements from android.webkit.WebView in my native app. As you can see in the uiautomatorviewer, I am...
Read more >
How to Identify WebView Elements in Android Hybrid App?
Did you try enabling “Enable view attribute inspection” in “Developer Options” on Android device. If it still doesn't work once disable and enable...
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