Appium: SafariLauncher navigates to apple.com instead of specified URL

Hi fabian…

After driver initiation use below code to switch to web view,

      //iOS driver initialization
        driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                capabilitiesIOS);
        Thread.sleep(11000);
        // To Switch focus to webview
        Set<String> contextNames = ((AppiumDriver) driver)
                .getContextHandles();

        for (String contextName : contextNames) {

            System.out.println("******contextName " + contextName);

            if (contextName.contains("WEBVIEW")) {

                ((AppiumDriver) driver).context(contextName);

            }
        }

Hi Rashmi!

Thank you !!! :slight_smile:
This solution is solved my problem!!! :slight_smile:

How to kill all the opened safari windows before launching safari browser on iPhone devices using appium. The problem i am getting is ,Safari browser is launching with SafariLauncher ,I am not able close all the remaining opened browsers.

Can any share the approach for ruby and watir / Webdriver. It working fine for me when using Java like below.
Set contextNames=null;

capabilities.setCapability(“platformName”, “iOS”);
capabilities.setCapability(“deviceName”, “iPhone 6 Plus”);
capabilities.setCapability(“browser”, “safari”);
capabilities.setCapability(“safariAllowPopups”, false);
capabilities.setCapability(“safariIgnoreFraudWarning”, true);
String deviceUDID=“1b70c7f91ea5cb1eeff649b6e41aa686ecae1d1d”;

capabilities.setCapability(“udid”,deviceUDID);
driver = new IOSDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

contextNames=driver.getContextHandles();

for(String contextName : contextNames){
if(contextName.contains(“WEBVIEW”)){
driver.context(contextName);
break;
}
}

driver.get(“https://www.google.co.in”);

2017-01-11 05:20:42:733 - info: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: Could not navigate to webview! Err: Error: connect ECONNREFUSED 127.0.0.1:27753)”,“origValue”:“Could not navigate to webview! Err: Error: connect ECONNREFUSED 127.0.0.1:27753”},“sessionId”:null}
2017-01-11 05:20:42:735 - info: <-- POST /wd/hub/session 500 35339.308 ms - 280

Hello All,

How to kill all the opened safari windows before launching safari browser on iPhone devices using appium. The problem i am getting is ,Safari browser is launching with SafariLauncher ,I am not able close all the remaining opened browsers and launching browser with default google page.

Please help me out on this issue.

Thanks in advance.

Regards,
Prasad