Appium is not loading all elements in DOM and i am unable to detect webview elements after switching context for the second time


  • I am using appium 2.0 with c#. I am automating an Android app with UIAutomator2.
    The app has a Login web view.

  • Before each test, logging is required and after each test logging out is required. This means that the login webview will be opened once for each test.

  • The tests are failing on real device that is running Android 11 with Android system webview version greater than 117.

  • Note that on emulator (Android 9 or Android 11) or (Real Device Android 9), i have no issues.

  • For the first few tests, I was able to find the elements on the login webview without the need of changing context. But at some point, after running a bunch of them, the DOM was not showing the whole tree of the login webview. I had to close the view and open it again and then the DOM will be loaded correctly.

  • I have set the WebView.SetWebContentsDebuggingEnabled(true) and chrome inspector was showing the elements. Even the app was showing the login web view but at some point the DOM wasn’t showing all elements. See the screenshots below.

  • I tried to change the context from NATIVE_APP to webview and then from web view to native.
    The first time it worked fine and i was able to detect the elements as HTML elements.
    However, the second time I change the context back from native to webview, the url and page source does not load. and i won’t be able to find the element. I have set a debuger on the Driver.PageSource and it showed “err_unknown_url_scheme”. (I am facing this issue on emulator too)

  • Here is the appium server log when i change context manually. The end of the logs shows the second time i change context and try to get the Driver.PageSource;
    AppiumServerLogs.log (220.0 KB)