Unable to locate elements after switching to Webview on iOS


I have a use case where I need to switch from Native to Webview and then enter Username and password and clicking on connect should switch back to Native.

I am using Appium v1.7.1 , javascript for automation. Also started ios_webkit_debug_proxy

Here is the code I have written:
it(“should switch to webview and login”, function () {
return driver
.then(function (contexts) { // get list of available views. Returns array: [“NATIVE_APP”,“WEBVIEW_1”]
return driver.context(contexts[1]); // choose the webview context
return driver

Here are the Capabilities:
exports.iosRealDevice6plus = {
platformName: ‘iOS’,
platformVersion: ‘10.3.2’,
automationName: ‘Appium’,
deviceName: “LG iPhone6Plus”,
udid: “0f0995de314bc080ea0f0995de314bc080ea”,
bundleId: “com.xyz.XYZNative”,
browserName: ‘’,
autoWebView: ‘true’,
webkitResponseTimeout: “25000”,
clearSystemFiles: ‘true’,
noReset: ‘true’,
FullReset: ‘false’,
preventWDAAttachments: ‘true’

Here is the Actual Result:
It switches to WebView_1 but when it tries to find USERNAME field, it errors out as:

[waitForElementByName(“USERNAME”)] [elements(“name”,“USERNAME”)] Error response status: 13, , UnknownError - An unknown server-side error occurred while processing the command. Selenium error: An unknown server-side error occurred while processing the command. Original error: Error while executing atom: operation timed out

In Appium Logs:
[XCUITest] Executing command ‘setContext’
[iOS] Attempting to set context to ‘WEBVIEW_1’
[RemoteDebugger] WebKit debugger web socket connected to url: ws://localhost:27753/devtools/page/1
[MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/d1f909b9-71c6-44bc-b20f-774b8ef581f4/context 200 9 ms - 76
[HTTP] --> POST /wd/hub/session/d1f909b9-71c6-44bc-b20f-774b8ef581f4/elements {“using”:“name”,“value”:“USERNAME”}
[MJSONWP] Calling AppiumDriver.findElements() with args: [“name”,“USERNAME”,“d1f909b9-71c6-44bc-b20f-774b8ef581f4”]
[XCUITest] Executing command ‘findElements’
[BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[BaseDriver] Waiting up to 3000 ms for condition
[RemoteDebugger] Executing ‘find_elements’ atom in default context
[RemoteDebugger] Sending javascript command (function(){return function(){var k=this;functi…
[RemoteDebugger] Sending WebKit data: {“method”:“Runtime.evaluate”,“params”:{“objectGroup”:“console”,“includeCommandLineAPI”:true,“doNotPauseOnExceptionsAndMuteConsole”:true,“expression”:"(function(){return function(){var k=this;functi…
[RemoteDebugger] Webkit response timeout: 25000
[XCUITest] Connection to WDA timed out
[iProxy] recv failed: Operation not permitted
[MJSONWP] Encountered internal error running command: Error: Error while executing atom: operation timed out
at XCUITestDriver.callee$0$0$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/web.js:199:11)
at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session/d1f909b9-71c6-44bc-b20f-774b8ef581f4/elements 500 25015 ms - 218
[HTTP] --> DELETE /wd/hub/session/d1f909b9-71c6-44bc-b20f-774b8ef581f4 {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: [“d1f909b9-71c6-44bc-b20f-774b8ef581f4”]
[BaseDriver] Event ‘quitSessionRequested’ logged at 1508254539213 (08:35:39 GMT-0700 (PDT))
[Appium] Removing session d1f909b9-71c6-44bc-b20f-774b8ef581f4 from our master session list
[JSONWP Proxy] Proxying [DELETE /session/d1f909b9-71c6-44bc-b20f-774b8ef581f4] to [DELETE http://localhost:8100/session/3D2262E4-8266-485E-88A4-09EACC9AD7BB] with no body
[JSONWP Proxy] Got response with status 200: “{\n “value” : {\n\n },\n “sessionId” : “10A68701-8378-4A04-B054-E1C25190D4D4”,\n “status” : 0\n}”
[XCUITest] Not changing permissions of ‘/Users/uName/Library/Developer/Xcode/DerivedData/WebDriverAgent-dikkwtrisltbeobjmfvpthwwekvs/Logs/Test/Attachments’ to ‘755’, because the other session does not expect them to be changed
[XCUITest] Cleaning test logs in ‘/Users/uName/Library/Developer/Xcode/DerivedData/WebDriverAgent-dikkwtrisltbeobjmfvpthwwekvs/Logs’ folder
[iOS] Clearing log files
[iOS] Deleting ‘/Users/uName/Library/Developer/Xcode/DerivedData/WebDriverAgent-dikkwtrisltbeobjmfvpthwwekvs/Logs’. Freeing 14M.
[iOS] Finished clearing log files
[XCUITest] In a web session. Removing remote debugger
[RemoteDebugger] Disconnecting from WebKit remote debugger
[iOSLog] Stopping iOS log capture
[BaseDriver] Event ‘quitSessionFinished’ logged at 1508254539633 (08:35:39 GMT-0700 (PDT))
[MJSONWP] Received response: null
[MJSONWP] But deleting session, so not returning
[MJSONWP] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/d1f909b9-71c6-44bc-b20f-774b8ef581f4 200 421 ms - 76
[RemoteDebugger] WebKit remote debugger socket disconnected
[XCUITest] Connection to WDA timed out
[iProxy] recv failed: Operation not permitted

I am totally blocked here, please help me out . Thanks.