Switch App to browser and back to app


My scenario is :

  1. Click “register with Facebook” link in my native app.
  2. Enter gmail id as email and click Login button on facebook login page ( I can perform switch context on emulator).
  3. Click “Login into google” button
  4. https://account.google.com page opened in chrome browser to check the verify code email

I am not able to switch to chrome browser in #4, I don’t know the activity and package of google app here, so I can’t be call switchActivity().

Let me know if you know solution for this scenario.Thanks


@Aru1 when Chrome page will open try 2 things:

  1. driver.getPageSource() - you can see what you see
  2. if first will not help to see Chrome elements try switch context to webView and repeat pageSource.


Hi, is there any way to solve the problem for IOS?


Hi @Mayuresh_Shirodkar, did you get the solution for this. I am also facing the same issue. My scenario is i have to open the chrome , do some validation on chrome page and return back to app.

can Anybody help me . I am automating in both android and ios with laster versions.


Hi I am also facing this issue. Can anyone help me out with this. I click on a link in my app and it opens up the chrome browser. I want to get the url from chrome browser and switch to my native app.


For android just using tap on phone’s back button (using key event) should do: driver.pressKey(new KeyEvent(AndroidKey.BACK));

For iOS; after tapping on deep link it takes to safari browser.
Browser address element: //XCUIElementTypeOther/XCUIElementTypeTextField[@name=“Address”]

Identify this element and get the value attribute to assert or action on it.
How to switch back to native?
Tap on this element so that clear button gets displayed and tap on clear button. Once again type your app’s scheme name in safari address field (every iOS app will have a scheme name; get this from your developer) e.g: driver.getKeyboard().sendKeys(“schemename://\n”);
This would popup the deep link alert, identify this alert - open button and tap on it - this takes you back to the iOS native app (AUT).


Hi,It may be too late but it may be useful for other people.
You can do in following way:
//Alreday have driver created with default app which you want to test

//Here is point where you want to switch into another app
JavaScriptExecutor js = (JavaScriptExecutor)driver;
HashMap<String, String> map = new HasjMap<>();
map.put(“bundleId”,"")//ID of the app which you want to switch
js.executeScript(“mobile: lunachApp”, map)
… you can do what you want to do

//Switch to app1 again


Here’s how I did it for both iOS and Android (javascript)

returnToApp = async () => {
    if (this.device.platformName == 'Android') {
      await this.driver.pressKeycode(4)
    } else if (this.device.platformName == 'iOS') {
      await this.driver.execute('mobile: activateApp', { bundleId: 'com.my.app' })
    await this.driver.sleep(1000)