Appium Safari test hangs and didn't finish
<p>I'm running an Appium simple test using Safari on iOS simulator on Mac with the latest version of Xcode and Appium </p>

<p>but sometimes the test hangs with the message "Let's browse", nothing happens on the simulator or appium GUI.... </p>

<p>Screenshot
<a href="https://i.stack.imgur.com/k8m3Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k8m3Z.png" alt="enter image description here"></a></p>

<p>Here is my tests code</p>

<pre><code>DesiredCapabilities capabilities = new DesiredCapabilities();

        //Emulator
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 6");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2");
        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");    

        //driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

@Test
    public void WebPageFormTest() throws Exception {
        driver.get("http://saucelabs.com/test/guinea-pig");
        Thread.sleep(2000);
        WebElement idElement = driver.findElement(By.id("i_am_an_id"));
        assertNotNull(idElement);
        assertEquals("I am a div", idElement.getText());
        WebElement commentElement = driver.findElement(By.id("comments"));
        assertNotNull(commentElement);
        commentElement.sendKeys("This is an awesome comment");
        WebElement submitElement = driver.findElement(By.id("submit"));
        assertNotNull(submitElement);
        submitElement.click();
        Thread.sleep(2000);
        WebElement yourCommentsElement = driver.findElement(By.id("your_comments"));
        assertNotNull(yourCommentsElement);
        assertTrue(driver.findElement(By.id("your_comments")).getText().contains("This is an awesome comment"));
        System.out.println(driver.getCurrentUrl());
    }
</code></pre>

<p>Here is the log info</p>

<pre><code>ionIdentifierKey":"6731e33c-c389-4d09-994c-f78fb7e22110"},"__selector":"_rpc_reportIdentifier:"}
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRSimulatorBuildKey":"13C75","WIRSimulatorProductVersionKey":"9.2","WIRSimulatorNameKey":"iPhone"},"__selector":"_rpc_reportSetup:"}
info: [debug] [REMOTE] Sim name: iPhone
info: [debug] [REMOTE] Sim build: 13C75
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRApplicationDictionaryKey":{"PID:30210":{"WIRApplicationIdentifierKey":"PID:30210","WIRIsApplicationProxyKey":false,"WIRApplicationNameKey":"Safari","WIRApplicationBundleIdentifierKey":"com.apple.mobilesafari","WIRIsApplicationActiveKey":1}}},"__selector":"_rpc_reportConnectedApplicationList:"}
info: [debug] Using remote debugger app key: PID:30210
info: [debug] [REMOTE] Selecting app PID:30210 (try #1 of 8)
info: [debug] [REMOTE] Sending _rpc_forwardGetListing: message to remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRConnectionIdentifierKey":"6731e33c-c389-4d09-994c-f78fb7e22110","WIRApplicationIdentifierKey":"PID:30210"},"__selector":"_rpc_forwardGetListing:"}
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30223","WIRIsApplicationProxyKey":true,"WIRApplicationNameKey":"","WIRApplicationBundleIdentifierKey":"com.apple.WebKit.WebContent","WIRIsApplicationActiveKey":1,"WIRHostApplicationIdentifierKey":"PID:30210"},"__selector":"_rpc_applicationConnected:"}
info: [REMOTE] We were notified we connected to possibly the wrong app. Using the id key suggested and trying again
info: [debug] [REMOTE] Selecting app PID:30223 (try #2 of 8)
info: [debug] [REMOTE] Sending _rpc_forwardGetListing: message to remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRConnectionIdentifierKey":"6731e33c-c389-4d09-994c-f78fb7e22110","WIRApplicationIdentifierKey":"PID:30223"},"__selector":"_rpc_forwardGetListing:"}
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30230","WIRIsApplicationProxyKey":true,"WIRApplicationNameKey":"","WIRApplicationBundleIdentifierKey":"com.apple.WebKit.WebContent","WIRIsApplicationActiveKey":1,"WIRHostApplicationIdentifierKey":"PID:30210"},"__selector":"_rpc_applicationConnected:"}
info: [REMOTE] We were notified we connected to possibly the wrong app. Using the id key suggested and trying again
info: [debug] [REMOTE] Selecting app PID:30230 (try #3 of 8)
info: [debug] [REMOTE] Sending _rpc_forwardGetListing: message to remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRConnectionIdentifierKey":"6731e33c-c389-4d09-994c-f78fb7e22110","WIRApplicationIdentifierKey":"PID:30230"},"__selector":"_rpc_forwardGetListing:"}
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30210","WIRListingKey":{}},"__selector":"_rpc_applicationSentListing:"}
info: [REMOTE] Empty page dictionary received. Trying again.
info: [debug] [REMOTE] Se
lecting app PID:30230 (try #4 of 8)
info: [debug] [REMOTE] Sending _rpc_forwardGetListing: message to remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRConnectionIdentifierKey":"6731e33c-c389-4d09-994c-f78fb7e22110","WIRApplicationIdentifierKey":"PID:30230"},"__selector":"_rpc_forwardGetListing:"}
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30223","WIRListingKey":{"1":{"WIRTitleKey":"Appium/welcome","WIRTypeKey":"WIRTypeWeb","WIRURLKey":"http://127.0.0.1:4723/welcome","WIRPageIdentifierKey":1}}},"__selector":"_rpc_applicationSentListing:"}
info: [debug] [REMOTE] Connected to app PID:30223 [[{"id":1,"title":"Appium/welcome","url":"http://127.0.0.1:4723/welcome","isKey":false}]]
info: [debug] Picking webview WEBVIEW_1
info: [debug] Attempting to set context to 'WEBVIEW_1'
info: [debug] [REMOTE] Selecting page 1 and forwarding socket setup
info: [debug] [REMOTE] Sending _rpc_forwardSocketSetup: message to remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30230","WIRConnectionIdentifierKey":"6731e33c-c389-4d09-994c-f78fb7e22110","WIRSenderKey":"6818a56b-8c02-4491-b1d9-872c88a69678","WIRPageIdentifierKey":1},"__selector":"_rpc_forwardSocketSetup:"}
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30230","WIRListingKey":{"1":{"WIRTitleKey":"Google","WIRTypeKey":"WIRTypeWeb","WIRURLKey":"https://www.google.com/?client=safari&amp;channel=iphone_bm","WIRPageIdentifierKey":1}}},"__selector":"_rpc_applicationSentListing:"}
info: [debug] Remote debugger notified us of a new page listing
info: [debug] We don't appear to have window set yet, ignoring
info: [debug] [REMOTE] Set sender key
info: [debug] [REMOTE] Sending _rpc_forwardSocketData: message to remote debugger
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30230","WIRListingKey":{"1":{"WIRTitleKey":"Google","WIRTypeKey":"WIRTypeWeb","WIRURLKey":"https://www.google.com/?client=safari&amp;channel=iphone_bm","WIRPageIdentifierKey":1}}},"__selector":"_rpc_applicationSentListing:"}
info: [debug] Remote debugger notified us of a new page listing
info: [debug] We don't appear to have window set yet, ignoring
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] got applicationSentData response
info: [debug] [REMOTE] Enabled activity on page
info: [debug] [REMOTE] Unregistering from page readiness notifications
info: [debug] [REMOTE] Page loading
info: [debug] [REMOTE] Waiting for dom...
info: [debug] [REMOTE] Page loaded, verifying whether ready through readyState
info: [debug] [REMOTE] Receiving data from remote debugger
info: [debug] [REMOTE] {"__argument":{"WIRApplicationIdentifierKey":"PID:30230","WIRIsApplicationProxyKey":true,"WIRApplicationNameKey":"","WIRApplicationBundleIdentifierKey":"com.apple.WebKit.WebContent","WIRIsApplicationActiveKey":1,"WIRHostApplicationIdentifierKey":"PID:30210"},"__selector":"_rpc_applicationDisconnected:"}

info: [debug] [REMOTE] Checking document readyState
info: [debug] [REMOTE] Sending javascript command
info: [debug] [REMOTE] Sending _rpc_forwardSocketData: message to remote debugger

info: --&gt; GET /wd/hub/status {}

info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"3a82a9f1-703f-4112-aa57-b39da2e69293"}
info: &lt;-- GET /wd/hub/status 200 6.989 ms - 179 {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"},"isShuttingDown":false},"sessionId":"3a82a9f1-703f-4112-aa57-b39da2e69293"}

info: --&gt; GET /wd/hub/status {}
</code></pre>